Jump to content


accessing a specific instance of a $_FILES array

  • Please log in to reply
2 replies to this topic

#1 isaaccs

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 10 September 2006 - 07:51 PM


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...

#2 HuggieBear

  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 10 September 2006 - 08:14 PM

Perhaps you could post your code, I see nothing impossible about this request.

Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 isaaccs

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 10 September 2006 - 08:27 PM


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>";

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users