Jump to content

PHP file upload problem


lyntaff

Recommended Posts

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 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");[/color][/size]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.