dougou8573 2013-03-26 01:22
浏览 38

PHP mkdir失败没有错误

I've am trying to set up a small file sharing server on my home's local network and am running into some big problems with the uploader. the step it seems to be failing on is the directory creation step however, when I first posted this there were no errors in the Apache log files however, that turned out to be the result of a permission problem with the lag files.

this are the relevant log entries.

[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

it confuses me because I have run sudo chmod 0777 /server/* sudo chmod 0777 /server with /server/ being the rood directory.

my code is as follows

<?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";
  }
?>

the output is as follows

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:

and the code calling it is

<form enctype="multipart/form-data" action="upload_movie.php" method="POST">
<input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

i have tried all the suggestions in PHP mkdir: Permission denied problem and I have selinux turned off. I am using fedora 17. the server is being run on an ext4 partition which contains nothing else.

as was suggested in comments, i tried $error = error_get_last(); echo $error['message']; which yealded Undefined index: file

  • 写回答

2条回答 默认 最新

  • douling6469 2013-03-26 04:59
    关注

    You seem to have set the correct permissions to the /server-directory. But your server wants to write to the /downloads- directory. You should be up and running with this command:

    Sudo chmod 777 /download
    
    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题