NYCPHP Meetup

NYPHP.org

[nycphp-talk] "Approach Review" for storing $_FILES in session variable and using later

Phillip Powell phillip.powell at adnet-sys.com
Tue Jun 8 16:23:56 EDT 2004


The approach I took I thought would be the best way to handle this, but 
I'm running into a snag which I'll explain in a minute.

I have a page with form elements whereby the user can upload a file.  
The user can also optionally associate this to-be-uploaded file with 
metadata.  When the user chooses to associate the to-be-uploaded file 
with metadata, they are taken to another page to do so, all the while, I 
am doing this:

$_SESSION['uploadedFile'] = serialize($_FILES);

I am retaining the $_FILES collection because you are not yet submitting 
anything but you want to not have to have the user re-submit the file 
over and over ad infinitum.  So on doing that, once they're done they 
hit the "Submit" button to do their duty.

I also have an Accepter class that will check all form data for 
validation.  If $_FILES exists (the user submitted a file), it needs to 
check to see if the file data is correct.  Everything works just fine... 
except for one problem:

is_uploaded_file($_FILES[$section]['tmp_name']) is always false because 
while $_FILES[$section]['tmp_name'] exists, it's obviously.. not 
uploaded, at least not immediately.

I re-retrieve and repopulated $_FILES as so:

if ($hasUploadedFileInAssoc && !$willDisassocNewAssocFile)
 $_FILES = unserialize($_SESSION['uploadedFile']);

then you finally get to:

if (!is_uploaded_file($_FILES[$section]['tmp_name'])) 
$this->setErrorArray(array('action' => 'File was not uploaded'));

This line is constantly false even though I did upload the file.. just 
not immediately before I get to the page with this line; it was uploaded 
a while ago and all information saved in a $_SESSION variable to be 
retrieved later.

What I'm looking for is a "code review" or an "approach review" as to 
whether or not I handled this request properly inasmuch as storing 
$_FILES into a session variable and retrieving it later to allow the 
user to upload a file and submit data anytime they want to on it.  This 
would help me moreso than a solution at this point to the 
is_uploaded_file() problem (though that's always welcomed too!)

Thanx
Phil

-- 
---------------------------------------------------------------------------------
Phil Powell
Multimedia Programmer
BPX Technologies, Inc.
#: (703) 709-7218 x107 
Fax: (703) 709-7219

	




More information about the talk mailing list