我在Mac上使用xampp。我有以下腳本,我試圖用它來上傳文件到文件夾:啓用文件夾上的權限以允許文件上傳。
upload.php的
<?php
$allowedExts = array("gif", "jpeg", "jpg", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
{
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("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
上傳的形式很簡單:
的index.html在htdocs目錄
<html>
<body>
<form action="upload.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>
我的文件夾結構是:
-/htdocs
-index.html
-upload.php
-/upload
當我運行該腳本,我得到以下錯誤:
Warning: move_uploaded_file(upload/dirt.png) [function.move-uploaded-file]: failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/development/Templates/PHP&JS/Upload Files to Server/form upload/upload.php on line 29
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/Applications/XAMPP/xamppfiles/temp/phpAQWDB1' to 'upload/dirt.png' in /Applications/XAMPP/xamppfiles/htdocs/development/Templates/PHP&JS/Upload Files to Server/form upload/upload.php on line 29 Stored in: upload/dirt.png
如何更改上傳文件夾的屬性,允許上傳文件?我有一個配置文件,我應該包括啓用這個?
運行'chmod'對上傳的文件夾設置適當的權限的文件夾路徑。看看[這個Apache Friends](http://www.apachefriends.org/f/viewtopic.php?p=144737)線程。 – Anne