Jump to content

Problem with file upload script!


Solarpitch

Recommended Posts

Hey,

 

I am trying to implement the below script but no matter what file type I upload, it will not upload the file. I keep getting the error "Invalid File"

 

Here's the code...

 


************************************** PHP

if (($_FILES["userfile"]["type"] == "image/gif")
|| ($_FILES["userfile"]["type"] == "image/pjpeg")
&& ($_FILES["userfile"]["size"] < 20000))
  {
  if ($_FILES["userfile"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["userfile"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["userfile"]["name"] . "<br />";
    echo "Type: " . $_FILES["userfile"]["type"] . "<br />";
    echo "Size: " . ($_FILES["userfile"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["userfile"]["tmp_name"] . "<br />";

    if (file_exists("/user_images/" . $_FILES["userfile"]["name"]))
      {
      echo $_FILES["userfile"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["userfile"]["tmp_name"],
      "/user_images/" . $_FILES["userfile"]["name"]);
      echo "Stored in: " . "/user_images/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }


************************************** HTML

... form1"  enctype="multipart/form-data".......

<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<input  name="userfile" type="file" id="menu_textbox" />


 

Just looking for a bit of help, thanks.

Link to comment
https://forums.phpfreaks.com/topic/51104-problem-with-file-upload-script/
Share on other sites

if (($_FILES["userfile"]["type"] == "image/gif")

|| ($_FILES["userfile"]["type"] == "image/pjpeg")

&& ($_FILES["userfile"]["size"] < 20000))

 

try adding .jpg to it as well as i had the same problem with pjpeg

 

if (($_FILES["userfile"]["type"] == "image/gif")
|| ($_FILES["userfile"]["type"] == "image/pjpeg")
|| ($_FILES["userfile"]["type"] == "image/jpeg")
&& ($_FILES["userfile"]["size"] < 20000))

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.