dpstir0081 2016-11-13 09:01
浏览 60

在linux中通过php创建文本文件

I am trying to create new text file through php by the following command:-

<?php
    $new = fopen('newfile.txt', 'w');
?>

Somehow it is unable to create it because of permissions issues of linux. Now I can only create text file first then set it's permissions. Or is there a way to do this in the code itself? Either way I need to get the job done.

  • 写回答

1条回答 默认 最新

  • douxin1956 2016-11-13 09:06
    关注

    You can create the directory and give it 744 permissions

    $dir = 'output';
    
     if ( !file_exists($dir) ) {
         $mask = umask(0);  // helpful when used in linux server  
         mkdir ($dir, 0744);
     }
    
     file_put_contents ($dir.'/test.txt', 'Hello File');
    
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!