I have a feature on my website where users can create an album to organize their photos better. They can upload new photos or they can select from photos they have already uploaded. In my PHP I have code that goes through the files they uploaded, if they uploaded any new ones. It works great, but I only want it to work when they ACTUALLY upload NEW photos. Right now, it runs even if they selected already uploaded, old photos. I am using the HTML5 "multiple" attribute so they can upload multiple photos. In my PHP, how can I write a conditional if statement to only run this code when they upload photos?
foreach ($_FILES['uploads']['name'] as $key => $file) {
$time= time();
$target= UPLOADPATH . $time . $file;
move_uploaded_file($_FILES['uploads']['tmp_name'][$key], $target);
}
I have tried using:
if ($_FILES['uploads']['size'] != 0)
if ($_FILES != 0)
if ($_FILES['upload']['name'] !=0)
But, so far no success. What can I do? What am I doing wrong?
Thanks
UPDATE
I ended up setting a variable to the value of the first element in the $_FILES array.
Like so:
$file_test= $_FILES['uploads']['size']['0'];
Then I used it in the test condion:
($file_test != 0) {
// run the code;
}
Thanks everyone for the help!!
if (! empty($_FILES))should do the trick.empty()doesn't work on files. Theenctypeincludes it in the post, regardless if it has bytes or not.var_dump($_FILES['uploads']['size']);