$_FILES array is not empty upon uploading nothing

JaiHO

New Member
Here is the form\[code\]form action="index.php" method="POST" enctype="multipart/form-data" > <input type="file" name="image[]" multiple="multiple"> <input type="submit" value="http://stackoverflow.com/questions/12538718/upload"> </form> \[/code\]I am trying to only run my code when only when \[code\]if(!empty($_FILES['image'])){\[/code\] but for some reason the array is not empty upon submitting no files and only clicking submit.Here is the rest of the code if that will help, thanks.\[code\]<html>\[/code\]Image Upload\[code\] <form action="index.php" method="POST" enctype="multipart/form-data" > <input type="file" name="image[]" multiple="multiple"> <input type="submit" value="http://stackoverflow.com/questions/12538718/upload"> </form> <?php include 'connect.php'; if(!empty($_FILES['image'])){ echo $_FILES['image']['error']; $allowed = array('jpg', 'gif', 'png', 'jpeg'); $count = 0; foreach($_FILES['image']['name'] as $key => $name){ $image_name = $name; $tmp = explode('.', $image_name); $image_extn = strtolower(end($tmp)); //can only reference file $image_temp = $_FILES['image']['tmp_name'][$count]; $filesize = filesize($_FILES['image']['tmp_name'][$count]); $count = $count +1; if(count($_FILES['image']['tmp_name']) > 5){ echo "You can upload a maximum of five files."; break; } else if(in_array($image_extn, $allowed) === false){ echo $name." is not an allowed file type<p></p>"; } else if($filesize > 1024*1024*0.3){ echo $name." is too big, can be a maximum of 3MB"; } else{ $image_path = 'images/' . substr(md5($name), 0, 10) . '.' . $image_extn; move_uploaded_file($image_temp, $image_path); mysql_query("INSERT INTO store VALUES ('', '$image_name', '$image_path')") or die(mysql_error()); $lastid = mysql_insert_id(); $image_link = mysql_query("SELECT * FROM store WHERE id = $lastid"); $image_link = mysql_fetch_assoc($image_link); $image_link = $image_link['image']; echo "Image uploaded.<p></p> Your image: <p></p><a href = http://stackoverflow.com/questions/12538718/$image_link>$image_path</a>"; } } } else{ echo "Please select an image."; } ?>\[/code\]
 
Top