为什么我的PHP脚本文件模式会创建一个文件? [英] Why can't my PHP script chmod a file it creates?

查看:132
本文介绍了为什么我的PHP脚本文件模式会创建一个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个创建一个需要执行(这是需要由系统中运行的批处理文件)的文件一个PHP。出于某种原因,即使文件被Apache拥有和PHP运行的Apache和文件被创建,脚本在去世使用chmod线。我需要做什么以不同的配置为允许PHP和chmod它创建的文件吗?上面两行是愉快地创造了这个文件,它chmods 755权,因为它创建一个目录。我失去了一些东西明显?

我搭配chmod行看起来是这样的:

  $ uploadFilePath =./path/to/file/;
    如果(!is_dir($ uploadFilePath)){
          的mkdir($ uploadFilePath,0777,真)或死亡(错误:无法创建目录'$ uploadFilePath');
    }
        ...
    //写批处理文件
      ...
    CHMOD($ uploadFilePath'sftp.batch,0777)或死亡(\\ ncan't搭配chmod$ uploadFilePath'sftp.batch');


解决方案

最有可能是由于的的umask 。尝试将它设置为 0 之前的搭配chmod

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');

解决方案

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

这篇关于为什么我的PHP脚本文件模式会创建一个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆