PHP File Upload / move_uploaded_file Not Working
21,025
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
Author by
SB2055
Updated on August 01, 2020Comments
-
SB2055 almost 4 years
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. ========
-
SB2055 over 12 yearsI appended the following to the beginning of my code: mkdir("C:/inetpub/wwwroot/PHP_Ramp/upload/", 0766); and I'm still getting "move failed".
-
anjunatl over 12 yearsHe 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.
-
WWW over 12 yearsThe
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. -
SB2055 over 12 yearsCool, I got it! Just had to give write permission to IIS through right-click>properties>security.
-
LeggoMaEggo over 8 yearsOf course! Thank you. Linux systems man:
sudo chmod -R a+w directoryhere