Why can't my PHP script chmod a file it creates?

白昼怎懂夜的黑 提交于 2019-12-12 11:08:23

问题


I have a php that creates a file that needs to be executable (it's a batch file that needs to be run by the system). For some reason, even though the file is owned by apache and php is running as apache, and the file IS created, the script dies at the chmod line. What do I need to configure differently to allow the php to chmod the file it creates? Two lines above it happily creates a directory FOR this file which it chmods to 755 right as it creates it. Am I missing something obvious?

my chmod line looks like this:

    $uploadFilePath = "./path/to/file/";
    if(!is_dir($uploadFilePath)){
          mkdir($uploadFilePath, 0777 , true) or die("ERROR:can't create directory '$uploadFilePath'");
    }
        ...
    //write batch file
      ...
    chmod ($uploadFilePath . 'sftp.batch' ,0777 ) or die ("\ncan't chmod  " . $uploadFilePath . 'sftp.batch');

回答1:


Most probably due to umask. Try setting it to 0 prior to the chmod.



来源:https://stackoverflow.com/questions/5697595/why-cant-my-php-script-chmod-a-file-it-creates

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!