我在 Mac 上使用 xampp。我有以下脚本,我试图用它来将文件上传到文件夹:
上传.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";
}
?>
上传表单很简单:
索引.html
<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 中的文件夹结构是:
-/htdocs
-index.html
-upload.php
-/upload
当我运行脚本时,我收到以下错误:
警告:move_uploaded_file(upload/dirt.png) [function.move-uploaded-file]:无法打开流:/Applications/XAMPP/xamppfiles/htdocs/development/Templates/PHP&JS/Upload Files to Server/form upload 中的权限被拒绝/upload.php 在第 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
How do I change the properties of the upload folder to allow uploading of files? I there a config file I should include to enable this?