Page 1 of 1

is it possible to store $_FILE into $_SESSION

Posted: Thu May 18, 2006 12:30 pm
by jonwondering
Does anybody know if it is possible to store $_FILE into $_SESSION successfully. I am trying to get rid of $_POST variables... I store everything into session, instead of having it in $_POST array on a form. That way when the user hits the Refresh button, it won't give that screen/message that page has expired. But I don't know how to handle the form that uploads images. Is it even possible to get rid of post variables ($_file) in that form?

thanks.

Re: is it possible to store $_FILE into $_SESSION

Posted: Thu May 18, 2006 12:50 pm
by Chris Corbyn
jonwondering wrote:Does anybody know if it is possible to store $_FILE into $_SESSION successfully. I am trying to get rid of $_POST variables... I store everything into session, instead of having it in $_POST array on a form. That way when the user hits the Refresh button, it won't give that screen/message that page has expired. But I don't know how to handle the form that uploads images. Is it even possible to get rid of post variables ($_file) in that form?

thanks.
You'll want to write a function to do it. The steps are:

1. Read $_FILES['foo']['tmp_name']
2. Use move_uploaded_file() to copy the file to your own tmp location
3. Switch $_FILES['foo']['tmp_name'] to be that new location
4. Copy $_FILES to the session

References will bail on something like this so just do a plain copy.

Posted: Thu May 18, 2006 12:53 pm
by Gambler
I recommend you to simply use GET. IIRC, you can stick files into get variable on modern browsers.

Note: If you use Firefox, it carries post variables through refresh.

Posted: Thu May 18, 2006 12:55 pm
by Chris Corbyn
Gambler wrote:I recommend you to simply use GET. IIRC, you can stick files into get variable on modern browsers.

Note: If you use Firefox, it carries post variables through refresh.
Hmm.... how does GET transport file data? Does the data appear in the URL? (I thought URL's had a maximum length). :)

Posted: Thu May 18, 2006 1:04 pm
by jonwondering
I see what you are saying d11wtq, I did the same thing you recommend except I converted $_file into $_session before uploading the image... that must've been the mistake :( I'll try it that way. Thanks.

Posted: Thu May 18, 2006 1:40 pm
by Chris Corbyn
jonwondering wrote:I see what you are saying d11wtq, I did the same thing you recommend except I converted $_file into $_session before uploading the image... that must've been the mistake :( I'll try it that way. Thanks.
One thing to bear in mind. Once you've moved the file the move_uploaded_file() and is_uploaded_file() functions will not work correctly on the new file.

Posted: Thu May 18, 2006 1:52 pm
by Gambler
I thought URL's had a maximum length
Not in RFC. Although, I can't find any documents that say how exactly you should upload through GET, so this might be just my imagination.

Posted: Thu May 18, 2006 2:13 pm
by jonwondering
i decided to go around the problem. once the form uploads the image(s), it redirects to itself one time, that way all $_POST and $_FILE variables are gone. all the information i needed, i stored when i was processing the images. thanks for your help d11wtq and Gambler.