vineld Posted July 28, 2009 Share Posted July 28, 2009 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? Quote Link to comment Share on other sites More sharing options...
gevans Posted July 28, 2009 Share Posted July 28, 2009 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"); } } ?> Quote Link to comment Share on other sites More sharing options...
vineld Posted July 28, 2009 Author Share Posted July 28, 2009 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... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.