# website upload



## binsky3333 (Aug 8, 2008)

Hi,
I am trying to make a website upload page, but i cant.
Here is my Form:

_<html>
<body><form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form></body>
</html>_

And here is my upload.php:

_<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
  {
  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";
  }
?>_

Basically im using http://w3schools.com/php/php_file_upload.asp
But whenever i try and upload something i get "invalid file"
BTW I AM USING XAMPP FOR TESTING!
Can anyone figure out whats wrong?


----------



## W1zzard (Aug 8, 2008)

var_dump($_FILES);
to see whats the input data you get fed


----------



## binsky3333 (Aug 8, 2008)

I am not good with php! So what do you mean by that?


----------



## Disparia (Aug 9, 2008)

_echo "Invalid file";_ is going to happen if the file is not a gif or jpeg, or if it's over 20KB.

Putting _var_dump($_FILES);_ at the start of the script (after the opening <?php tag) shows you the content of the $_FILES array, and thus the file type and size of the file you're trying to upload.


----------



## binsky3333 (Aug 10, 2008)

oh ok, thanks!


----------

