我試圖在我家的本地網絡上建立一個小型文件共享服務器,並遇到了上傳者的一些大問題。它似乎失敗的一步是目錄創建步驟,但是,當我第一次發佈時,Apache日誌文件中沒有錯誤,但是,結果證明是滯後文件的權限問題的結果。PHP mkdir失敗,沒有錯誤
這是相關的日誌條目。
[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
它混淆了我,因爲我已經運行 須藤chmod爲0777 /服務器/ * 須藤chmod爲0777 /服務器 與/服務器/是聖壇目錄。
我的代碼如下
<?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: Permission denied problem和我關閉了selinux。我正在使用fedora 17.服務器正在ext4分區上運行,其中不包含任何其他內容。我試過 $ error = error_get_last(); echo $ error ['message']; 哪些是yealded 未定義的索引:文件
您是否啓用了'error_reporting'?應該有一條消息,除非你的'/'根目錄是世界可寫的。 (不,不這樣做!) – mario 2013-03-26 01:24:54
添加這個來得到錯誤是什麼,它似乎是一種權限問題,任何方式嘗試代碼來獲取錯誤代碼:$ error = error_get_last(); echo $ error ['message']; – 2013-03-26 01:26:24
馬里奧是正確的,你應該或應該說,必須檢查你的目錄的權限。 – 2013-03-26 01:26:47