我想上傳文件到我的樹莓派3.我安裝Apache和PHP,這是網頁的index.php的內容:PHP move_uploaded_file()以deosn't工作
<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" />
</form>
<?php
if ($_FILES["userfile"]["size"] != 0 && $_FILES["userfile"]["tmp_name"] != "")
{
$uploaddir = "/var/www/html/";
$uploadfile = $uploaddir . $_FILES["userfile"]["name"];
try
{
echo '<pre>';
if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $uploadfile))
{
echo "File is valid, and was successfully uploaded.\n\n";
}
else
{
echo "File upload failed\n\n";
}
}
catch (Exception $e) { echo $e->getMessage()."\n"; }
echo "Array content:\n";
print_r($_FILES);
print "</pre>";
} ?>
當我上傳一個文件,甚至包含一些字節的文本文件,move_uploaded_file()返回false並且文件沒有上傳,但是沒有拋出異常並且$_FILES["userfile"]["error"]
的值爲0.文件夾/var/www/html/
的權限爲drwxr-xr-x
,所以它們應該夠了吧?
我試過,但它甚至沒有創建目錄,mkdir()不會拋出任何異常。也許apache沒有權限,但似乎很奇怪,我用'sudo systemctl start apache2.service'啓動它,也許我應該用另一種方式啓動它? –
檢查出許可bro可能你錯過了他們。 –
請回復它是否有效 –