Jump to content


PHP file upload problem

  • Please log in to reply
1 reply to this topic

#1 lyntaff

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 06 September 2006 - 11:46 AM

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:

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>";  

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";
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']);

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 member

if (!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");

#2 Woolf

  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 06 September 2006 - 10:53 PM

You could try using something along the lines of
  error stuff here...

That should, in theory, prevent uploading of files without names (in other words... not uploading anything).

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users