So I'm testing out the move_uploaded_file() php script from the w3schools website http://www.w3schools.com/php/php_file_upload.asp. Here is my code.
if ($_FILES["file"]["size"] < 2000000)
{
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("/var/www/upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
elseif(move_uploaded_file($_FILES["file"]["tmp_name"], "/var/www/upload/".$fileName))
echo "Stored in: " . "/var/www/upload/".$fileName;
}
}
else
echo "Invalid file";
The problem is if(move_uploaded_file($_FILES["file"]["tmp_name"],"/var/www/upload/".$fileName))
returns false all the time but it seems the file is stored in the tmp
folder on the server (for example: /tmp/php8rrKoW
). When I check the tmp
folder the file is not there. (It's supposed to get deleted after the script finish executing.) I also don't see the /php8rrkoW
folder. I'm not sure if it's supposed to be there. I set the permission for both the tmp
folder and /var/www/upload/
to 777
using chmod
, but I'm not sure if I should set the owner to apache
. So I want to know why the file isn't copied over to /var/www/upload
and if there is a way to test this.
Aucun commentaire:
Enregistrer un commentaire