Page 1 of 1

[SOLVED] problem with upload script

Posted: Tue Dec 29, 2009 10:15 am
by arbitter
I have this script from w3schools, but it doesn't work...
I do have a folder /upload so that's not the problem

Code: Select all

<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 10000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
 
    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>
And forgot to mention that when I try to upload an image, gif/jpg/... from a file size of less than 1 mb, it shows 'invalid file'...

Re: problem with upload script

Posted: Tue Dec 29, 2009 10:50 am
by daedalus__
is there an error message?

Re: problem with upload script

Posted: Tue Dec 29, 2009 11:32 am
by arbitter
Yes, there is an error message; 'invalid file'

Re: problem with upload script

Posted: Tue Dec 29, 2009 1:54 pm
by AbraCadaver
I assume that your file input on your form is name="file"?

Code: Select all

echo $_FILES["file"]["type"];

Re: problem with upload script

Posted: Tue Dec 29, 2009 2:05 pm
by arbitter
Indeed, it was calles 'uploadedfile'
Changed it all and it works perfectly now.

Thanks a lot for your help! It was a silly problem, but I'm still quite new to php.