Jump to content


This topic is now archived and is closed to further replies.


accessing a specific instance of a $_FILES array

Recommended Posts


I've been looking for hours on how to do this. It seems so simple, but I can't find the answer.

I've built an upload page that allows user to select and upload TWO files.

I've got a processing script, but it seems I can only deal with ONE of the uploaded files, or I can act on the array, but I can't seem to act on the two instances of the array independently of each other. Ie, I want the first file saved in a certain directory, and it's name stored as a variable for later use, and I want the second file stored in another location, and it's name stored seperatley as a variable for later use.

Any suggestions?

Thanks much...

Share this post

Link to post
Share on other sites
Perhaps you could post your code, I see nothing impossible about this request.


Share this post

Link to post
Share on other sites

thanks for the reply. i'm kind of new w/ php.

soo... here's the very basic processing script. it takes both of the uploaded files, displays their properties, and copies them to  the storage directory.

what i want it to do is: set the name of the file not derived from the local user's filename, rather from another value submitted as a $_POST (such that the user is basically renaming the file while uploading). there are two seperate fields being submitted (ie, name1 and name2) as post data from the form, in addition to the file upload.

i also want image1 to have a different $file_dir than image2... but i don't know how to do that...basically i don't know how to differentiate between the two instances of the $_Files, because I want to take seperate actions on each one.


$file_dir = ".../httpdocs/cathyhull/artwork_upload";

foreach ($_FILES as $file_name => $file_array) {
echo "path ".$file_array['tmp_name']. "<br>\n";
echo "name ".$file_array['name']. "<br>\n";
echo "type ".$file_array['type']. "<br>\n";
echo "size ".$file_array['size']. "<br>\n";

if (is_uploaded_file($file_array['tmp_name'])) {
move_uploaded_file($file_array['tmp_name'], "$file_dir/$file_array[name]") or die ("Couldn't complete");
echo "File upload complete!<br><br>";

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.