Jump to content

Functionality of the $_FILES array


vineld

Recommended Posts

I have seen plenty of examples, even in the php manual, where they only check to see if the $_FILES['whatevermynameis'] array is empty or not set although this do not seem to work properly. I often encounter that the array is always set after the form has been submitted no matter if a file has been uploaded or not so I normally check size instead. Why is this? What is actually the "correct" way to check if a file has been selected?

Link to comment
https://forums.phpfreaks.com/topic/167819-functionality-of-the-_files-array/
Share on other sites

If you see this example from php.net you'll see that you can check the error array key of the uploaded file(s)

 

<?php
foreach ($_FILES["pictures"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
        $name = $_FILES["pictures"]["name"][$key];
        move_uploaded_file($tmp_name, "data/$name");
    }
}
?>

Yeah, I have used that as well although if it's possible that the $_FILES['myname'] array is empty there will be no error either. Will the look of the array depend on the browser or is it php that decides? I think I still have PHP4 versions running in some places...

Archived

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

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