doujian3132 2013-12-02 14:19
浏览 75

chmod($ file)完全不像我想要的那样工作

I was using the chmod($path, $mode, bool) function, but it wasn't setting permissions correctly, so I am now trying:

$fp = fopen($path, 'w');
fclose($fp);
chmod($path, 0750);  //changed to add the zero
return true;

problem is when I use the first method it creates the path ok... something like this uploads/2013/name/1/file.pdf(correct) but the permissio0ns are incorrect.

when I use the second method it creates a file with no extension: uploads/2013/name/1(incorrect) but the permissions are correct...

Here is my code:

if($_POST["upload"]){

$year = date('Y');

//path to directory
$path = $_SERVER["DOCUMENT_ROOT"] . '/uploads/' . $year . '/' . strtolower(str_replace(' ','',$_POST["username"])) . '/' . $_POST["month"];

//path to file
$target_path = $path . '/' . basename($_FILES['uploadedfile']['name']);

$filename = basename($_FILES['uploadedfile']['name']);

/* $ext = substr($filename, strrpos($filename, '.') + 1); */

if(!is_dir($path) && !file_exists($target_path)) {

    mkdir($path, 0750, true);

    chmod($path, 0750, true);  //changed to add the zero

    if(($_FILES["uploadedfile"]["type"] == "application/pdf") && ($_FILES["uploadedfile"]["size"] < 550000)) {

        if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)){

            print "<div class='success'>The file " . "<span class='filename'>" . basename( $_FILES['uploadedfile']['name']) . "</span>" . " has been uploaded</div>";
        }
    } else {

        print "<div class='error'>Wrong file format</div>";

    }

} else {

    print "<div class='error'>File already exists!</div>";

}

}
  • 写回答

2条回答 默认 最新

  • douying9296 2013-12-02 14:32
    关注

    Looks like your running into an issue with umask try doing a:

    umask(0)
    

    in the beginning of your script.

    The default umask is fetched from your system configuration and is normaly 0022 and this is applied everytime you do a chmod in php so a chmod 0777 with a umask of 0022 turns into a 0755

    评论

报告相同问题?

悬赏问题

  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛