lyntaff Posted September 6, 2006 Share Posted September 6, 2006 I have a very annoying problem while running a script I created about 2 years ago.I have a basic script which uploads a file to a server path and information to a database. But evertime I execute without a file it doesn't work. I should get an error no.4 but for some reason an IF statement that checks the error gets bypassed until the scipt dies for being a wrong file type. Can anybody understand whats wrong?The code is this:[size=8pt][color=green]if ($_FILES['image1']['error']=="4") { mysql_query("UPDATE cars SET exterior_image = 'np.gif' WHERE car_id = $image_id"); echo "<div align='center'>The Car details have been added to the database successfully. The Cars Reference Number is: ".$image_id."<br><br> <a href='addcar.php'>Continue</a></div>"; exit; }if ($_FILES['image1']['size']=="50000") { echo "One of the uploaded images is to big, it must be under 50k. Please go back and try again"; exit; } if ($_FILES['image']['type'] != "image/gif" && $_FILES['image1']['type'] != "image/pjpeg" && $_FILES['image1']['type'] != "image/jpeg" && $_FILES['image']['type'] != "image/jpg") { die("<strong>Problem:</strong> Image 1 is not a valid image file, please go back and try again.<BR>Image Type: ".$_FILES['image1']['type']); exit; }if ($_FILES['image1']['type'] == "image/gif") { $ext = ".gif";} else if ($_FILES['image1']['type'] == "image/pjpeg") { $ext = ".jpg";} else if ($_FILES['image1']['type'] == "image/jpeg") { $ext = ".jpg";} else if ($_FILES['image1']['type'] == "image/jpg") { $ext = ".jpg";}$upfile = "/home/sites/alanevansmotors.co.uk/public_html/carpics/".$image_id . $ext; // $image_id being the id of the newly inserted memberif (!move_uploaded_file($_FILES['image1']['tmp_name'], $upfile)) { echo "<strong>Problem:</strong> Could not upload image onto server"; }mysql_query("UPDATE cars SET exterior_pic = '$image_id"."$ext' WHERE car_id = $image_id");[/color][/size] Quote Link to comment Share on other sites More sharing options...
Woolf Posted September 6, 2006 Share Posted September 6, 2006 You could try using something along the lines ofif(!isset($_FILES['image1']['name'])){ error stuff here...}That should, in theory, prevent uploading of files without names (in other words... not uploading anything). 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.