Bacysoft.cn

标题: failed to open stream: Permission denied [打印本页]

作者: bacy001    时间: 2011-7-25 18:51
标题: failed to open stream: Permission denied
本帖最后由 bacy001 于 2011-7-25 18:52 编辑

问题源码:
  1. <?php
  2.         $content = "Hello World!";
  3.         $file = "Hello.txt";
  4.         $handle = fopen($file,"w");

  5.         if (!is_writable($file))
  6.         {
  7.                 die ("File ".$file." cant write! Please Check first.");
  8.         }
  9.         if (!fwrite($file,$content))
  10.         {
  11.                 die ("Write ".$file." failed!");
  12.         }

  13.         fclose($file);

  14.         die ("Succeed!");

  15. ?>
复制代码
执行以上代码后出现如下错误提示:
  1. Warning: fopen(Hello.txt) [function.fopen]: failed to open stream: Permission denied in /home/www/wwwroot/example/1.php on line 4
  2. File Hello.txt cant write! Please Check first.
复制代码
错误分析: Permission denied 表明是权限错误,一般是服务器目录权限设置问题!

解决办法:
1、登录到服务器,找到本程序所在目录,假设为“example”;
2、执行命令“chown www:www example -R”;




欢迎光临 Bacysoft.cn (http://bacysoft.cn/) Powered by Discuz! X3.3