我正在尝试在我家的本地网络上设置一个小型文件共享服务器,但上传器遇到了一些大问题。它似乎失败的步骤是目录创建步骤,但是,当我第一次发布此内容时,Apache 日志文件中没有错误,但事实证明这是滞后文件权限问题的结果。
这是相关的日志条目。
[Mon Mar 25 18:43:05 2013] [error] [client 10.0.0.17] PHP Warning: mkdir(): Permission denied in /server/upload_movie.php on line 10, referer: http://10.0.0.17/upload_movie.html
它让我感到困惑,因为我已经运行 sudo chmod 0777 /server/* sudo chmod 0777 /server 并且 /server/ 是 rood 目录。
我的代码如下
<?php
echo "starting". "<br>";
$allowedExts = array("mp4", "mpg", "avi", "mkv");
$extension = end(explode(".", $_FILES["uplodedfile"]["name"]));
echo "filetype parsed". "<br>";
$path = "/downloads/movies/unsorted/";
echo "checking upload directory". "<br>";
if(!is_dir($path)){
echo "upload directory not found, creating...";
if (mkdir($path,0777,true))
{
echo "directory creation complete". "<br>";
}
else
{
echo "directory creation failed at ".$path."<br>";
}
}
echo "checking file". "<br>";
if (false)
{
echo "filetype and size passed". "<br>";
if ($_FILES["uplodedfile"]["error"] > 0)
{
header('Location: upload_failure.php?file='.$_FILES["uplodedfile"]['name'].'&error='.$_FILES["uplodedfile"]["error"]);
exit();
}
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["uplodedfile"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists on server. ". "<br>";
}
else
{
echo "creating perminant copy of file". "<br>";
move_uploaded_file($_FILES["uplodedfile"]["tmp_name"],
$path."/" . $_FILES["uplodedfile"]["name"]);
echo "Stored in: " . "movie_uploads/" . $_FILES["file"]["name"]. "<br>";
}
}
header('Location: upload_success.php?type=movie');
exit();
}
else
{
echo "error:<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Name: " . $_FILES["file"]["name"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
echo "extension: ".$extension;
exit();
// echo "Invalid file";
}
?>
输出如下
starting
filetype parsed
checking upload directory
upload directory not found, creating...directory creation failed at /downloads/movies/unsorted/
checking file
error:
Type:
Name:
Size: 0 kB
Temp file:
extension:
调用它的代码是
<form enctype="multipart/form-data" action="upload_movie.php" method="POST">
<input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
我已经尝试了PHP mkdir 中的所有建议:权限被拒绝问题,我关闭了 selinux。我正在使用 Fedora 17。服务器正在一个 ext4 分区上运行,该分区不包含其他任何内容。
正如评论中所建议的,我尝试了 $error = error_get_last(); 回声 $error['message']; 哪个是未定义的索引:文件