2

I have the following 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 the following script:

<?php
error_reporting(E_ALL);

if (($_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 />";


    $moved = move_uploaded_file($_FILES["file"]["tmp_name"], "C:/inetpub/wwwroot/PHP_Ramp/upload/" . $_FILES["file"]["name"]);

    if ($moved) {
        echo "Move: Success";
    }
    else {
        echo "Move Failed";
    }


      echo "Stored in: " . "C:/inetpub/wwwroot/PHP_Ramp/upload/" . $_FILES["file"]["name"];
      }
    }

else
  {
  echo "Invalid file";
  }
?>

For some reason I keep getting "Move Failed". Any idea why the file isn't moving?

======== SO thinks I need to explain this more; so I'm typing a sentence down here. ========

2
  • please include, while you're still typing, the full php error you see. This'll help a lot. Anyway; check if php safe mode is switched off (having it on and try to move uploaded files is probably the most common mistake made...) Commented Jan 6, 2012 at 15:12
  • Thanks for the reply giorgio. I'm using notepad++ - how would I go about looking at the full php error? I'm on IIS7. Also - I verified that safe mode was off in php.ini. Commented Jan 6, 2012 at 15:21

1 Answer 1

6

Check whether you have permissions in that folder (C:/inetpub/wwwroot/PHP_Ramp/upload/) to write file. You can check the folder by right clicking and selecting properties -> Security

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

5 Comments

I appended the following to the beginning of my code: mkdir("C:/inetpub/wwwroot/PHP_Ramp/upload/", 0766); and I'm still getting "move failed".
He means to make sure that the folder itself is writable by the PHP script. Adding 0766 is just modifying the moved file's permission once it's written.
The mode argument is ignored in Windows per us.php.net/manual/en/function.mkdir.php - I think @Shyju means NTFS permissions since @Mik said he's using IIS7.
Cool, I got it! Just had to give write permission to IIS through right-click>properties>security.
Of course! Thank you. Linux systems man: sudo chmod -R a+w directoryhere

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.