doutu6616 2014-01-25 07:05
浏览 67
已采纳

在unix环境中使用php写入.text文件,其中文件需要root权限

okay now this is utterly bewildering to me and I can't figure out why this script is not working basically I am attempting to write a line of data to a .txt file in php here is the part of the script which matters:

    set_include_path('/etc/apache2/rewrite/');
    if($_GET['type']=="14"){ //video is documentary
         $file = '/etc/apache2/rewrite/Documentaries.txt';
         $line= clean_url($content[0]['title']) . " " . $content[0]['content_id'] ."
";
         file_put_contents($file, $line, FILE_APPEND);

            echo "inseted into documentaries <br>" . $line;
    }else if ($_GET['type']=="17"){//video is a talk
         $file = '/etc/apache2/rewrite/Talks.txt';
         $line= clean_url($content[0]['title']) . " " . $content[0]['content_id'] ."
";
         file_put_contents($file, $line, FILE_APPEND);
            echo "inseted into talks";

    }else if($_GET['type']=="15"){//video is debate
         $file = '/etc/apache2/rewrite/Debates.txt';
         $line= clean_url($content[0]['title']) . " " . $content[0]['content_id'] ."
";
         file_put_contents($file, $line, FILE_APPEND);
                            echo "inseted into debates";
   }

and note that after this block i echo the $line which is something like this

   inside-nature-s-giants-the-leatherback-turtle 13443

and also the echo's inside the if statement are also echoe'd however nothing is modified in any of the files for a reason I can't seem to figure out I have given the script both write and execute permission and still can't seem to get this to work .. I am unsure what is going on As I use similar logic in other scripts without problem any help would be greatly greatly appreciated as I've sworn at my terminal a little to much for my liking Thanks, Brendan


*Update * I do not have the correct file permisions thanks to @SyntaxLAMP for reminding me to check error logs

okay here is the permision for the php file

-rwxrwxrwx 1 root root 9202 Jan 25 07:48 update_untagged.php

and the permisions of the three files I am attempting to write to

-rw-r--r-- 1 root root      7 Jan 25 05:05 Debates.txt
-rw-r--r-- 1 root root 110691 Jan 25 07:16 Documentaries.txt
-rw-r--r-- 1 root root  45747 Jan 25 05:05 Talks.txt

they both have the same permisions so I dont understand why this still isn't working any help with this would be greatly appreciated stil

  • 写回答

1条回答 默认 最新

  • dsimib1625 2014-01-25 08:23
    关注

    You need to give the user the script is running as access to those files. You can either give everyone access to them like this:

    chmod 666 Debates.txt Documentaries.txt Talks.txt
    

    Or set the owner to whatever the script runs as (possibly www-data):

    chown www-data Debates.txt Documentaries.txt Talks.txt
    

    Edit:

    Just to be clear, don't give everyone access unless there's a valid reason to do so, it's a lot safer just to change the owner to whatever the script runs as.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

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