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 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢