[SOLVED] problem with upload script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
arbitter
Forum Newbie
Posts: 24
Joined: Tue Dec 29, 2009 10:04 am

[SOLVED] problem with upload script

Post 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'...
Last edited by arbitter on Sun Jan 03, 2010 5:36 am, edited 2 times in total.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Re: problem with upload script

Post by daedalus__ »

is there an error message?
arbitter
Forum Newbie
Posts: 24
Joined: Tue Dec 29, 2009 10:04 am

Re: problem with upload script

Post by arbitter »

Yes, there is an error message; 'invalid file'
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: problem with upload script

Post by AbraCadaver »

I assume that your file input on your form is name="file"?

Code: Select all

echo $_FILES["file"]["type"];
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
arbitter
Forum Newbie
Posts: 24
Joined: Tue Dec 29, 2009 10:04 am

Re: problem with upload script

Post 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.
Post Reply