I don't understand why this is not working. It should be very easy.
upload.php :
$uploaddir = '/usr/share/nginx/www/pitfax/upload/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo "<p>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
}
else {
echo "Upload failed";
}
echo "</p>";
echo '<pre>';
echo 'Here is some more debugging info:';
print_r($_FILES); print "</pre>";
form page:
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
the error output is :
Upload failed
Here is some more debugging info:Array (
[userfile] => Array
(
[name] => test.pdf
[type] => application/pdf
[tmp_name] => /tmp/phptM0p4w
[error] => 0
[size] => 1287464
)
)
- Webserver : NginX
- Permissions for
upload.php: 644 - Permissions for
uploaddirectory : 755 - Working in SSH with root user.
- Edit : upload_max_filesize = 2M
- Edit : post_max_size = 8M
Another thing! After upload is done, I want to get absolute path of the uploaded file. (ex:/usr/share/nginx/www/pitfax/upload/test.pdf)
echo $uploadfile;and just double check that its not just trying to upload as a directory.$uploadfilebe onlyupload/test.pdf? There should be a full path there! If there is no upload directory at the place where the script is executing, that would explain whilemove_uploaded_filefails.