Serialize file resource
php, serialization
Solution
Resources are not intended to be serialized and cannot be persisted across page loads via session variables. They are basically just handles on some system resource. PHP will de-allocate these resource handles automatically at the end of script execution.
That being said, you can certainly place the file path you are working with in session and just get a new handle on it on subsequent page loads.
Problem
How can I serialize a resource ? An illustration : ``` <?php if ($_fileHandle = fopen('file.txt', 'a')) { echo "fopen success <br />"; } else { echo "fopen failed <br />"; } var_dump($_fileHandle);//displays "resource(3, stream)" $serializedResource = serialize($_fileHandle); $unserializedResource = unserialize($serializedResource); var_dump($unserializedResource);//displays "int 0" ?> ``` As you can see the resource returned by fopen is lost if serialized/unserialized as stated by the documentation : serialize() handles all types, except the resource-type I want to be able to serialize a resource to store it in session to make it available in every pages. May be there is another way ?