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 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退