我在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_upload_file(upload/dirt.png)[function.move upload file]:无法打开流:在/Applications/XAMPP/xamppfiles/htdocs/development/Templates/PHP中的权限被拒绝
警告:move_uploaded_file()[function.move上传文件]:无法移动'/应用程序/XAMPP/xamppfile/temp/phpAQWDB1'到'上传/dirt.png' /Applications/XAMPP/xamppfiles/htdocs/development/Templates/PHP
如何更改上载文件夹的属性以允许上载文件?我是否应该包含一个配置文件来启用此功能?
您需要运行该命令
chmod -Rf 777 FOLDER_PATH
这里FOLDER_PATH是存储图像的文件夹路径