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.
is it possible to store $_FILE into $_SESSION
Moderator: General Moderators
-
jonwondering
- Forum Commoner
- Posts: 39
- Joined: Mon Mar 13, 2006 6:26 pm
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: is it possible to store $_FILE into $_SESSION
You'll want to write a function to do it. The steps are: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.
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.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
-
jonwondering
- Forum Commoner
- Posts: 39
- Joined: Mon Mar 13, 2006 6:26 pm
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
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.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 mistakeI'll try it that way. Thanks.
-
jonwondering
- Forum Commoner
- Posts: 39
- Joined: Mon Mar 13, 2006 6:26 pm