Mauro F. Mauro F. - 1 year ago 67
PHP Question

PHP move_uploaded_file() deosn't work

I'm trying to upload file to my Raspberry Pi 3. I installed Apache and PHP and this is the content of the page index.php:

<form enctype="multipart/form-data" action="index.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="5000000" />
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />

if ($_FILES["userfile"]["size"] != 0 && $_FILES["userfile"]["tmp_name"] != "")
$uploaddir = "/var/www/html/";
$uploadfile = $uploaddir . $_FILES["userfile"]["name"];
echo '<pre>';
if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $uploadfile))
echo "File is valid, and was successfully uploaded.\n\n";
echo "File upload failed\n\n";
catch (Exception $e) { echo $e->getMessage()."\n"; }

echo "Array content:\n";

print "</pre>";
} ?>

When I upload a file, even a text file with some bytes in it, move_uploaded_file() returns false and the file is not uploaded, however no exception is thrown and the value of
is 0. The permission of the folder
, so they should be enough, right?

Answer Source

Apparently it was enough to run sudo chmod 777 /var/www/html/. I was quite sure that I did that already but probably I didn't do it correctly.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download