Jump to content

accessing a specific instance of a $_FILES array


isaaccs

Recommended Posts

Hi,

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...
Link to comment
Share on other sites

Hi,

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>";
}
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.