0

I used the codes(html+php script) below to upload image file

submit.html

<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>

php upload file upload_file.php

<?php

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

echo  "<br>";
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";
  }
?>

but it reported error:

image/jpeg
Upload: 02.jpg
Type: image/jpeg
Size: 54.2626953125 Kb
Temp file: /tmp/phpT617qx

Warning: move_uploaded_file(upload/02.jpg): failed to open stream: No such file or directory in /home/virtual/site18/fst/var/www/html/test/upload_file.php on line 29

Warning: move_uploaded_file(): Unable to move '/tmp/phpT617qx' to 'upload/02.jpg' in /home/virtual/site18/fst/var/www/html/test/upload_file.php on line 29
Stored in: upload/02.jpg

submit.html and upload_file.php are in same directory with mod 777

Welcome any comment

2
  • 2
    What are the permissions on upload/? Does the directory exist? Commented Sep 3, 2011 at 3:53
  • Thanks, you are right, I forgot to e create the directory, please open an answer, I will select it as correct answer Commented Sep 3, 2011 at 4:44

2 Answers 2

1

It could be because you should assign correct permissions for writing files into that file.

Sign up to request clarification or add additional context in comments.

Comments

0

What are the permissions on upload/? Does the directory exist?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.