file_put_contents() failed to open stream: Permission denied 问题解决(生成日志文件)

来源:互联网 发布:淘宝设计店铺 编辑:程序博客网 时间:2024/05/16 14:36
 

file_put_contents() failed to open stream: Permission denied 问题解决(生成日志文件)

 359人阅读 评论(0) 收藏 举报
 分类:
[php] view plain copy
  1. 很长时间没有写PHP了,今天突然有个需求要写一个保存文件的功能。  
  2.   
  3. function downloadFile( $url , $savePath = '' )  
  4. {  
  5.     $fileName = getUrlFileExt( $url );  
  6.     $fileName = rand(0,1000). '.' . $fileName ;  
  7.     $file = file_get_contents ( $url );  
  8.     file_put_contents ( $savePath . '/' . $fileName , $file );  
  9.     return $fileName ;  
  10. }  
  11.   
  12.    
  13.   
  14. 调用downloadFile(  "http://www.xxx.com"  ,  "/bak"  );  
  15.   
  16. 怎么都不行,一直提示file_put_contents() failed to open stream: Permission denied  
  17.   
  18. 后面把文件夹权限也加上还是不行,郁闷了。  
  19.   
  20. 最后突然想到地址不应该是相对的哦。  
  21.   
  22. 改为downloadFile(  "http://www.xxx.com"  ,  rtrim($_SERVER['DOCUMENT_ROOT'],'/')."/bak"  ); 搞定了,哎要是换成以前肯定一下就想到了。  
  23.   
  24.   
  25. 《《《《《《《《《《===============================================================================================》》》》》》》》  
  26.   
  27. <pre name="code" class="php">public function setDefaults(){  
  28.             $success"更新成功";  
  29.             $faild = "更新失败";      
  30.             $sql ="UPDATE config SET withdraw = 1000,max_money = 1000"//SQL语句  
  31.             $this->db->query($sql);  
  32.             if(mysql_error()){  
  33.                 $this->writelogs($faild);  
  34.                 return false;  
  35.             }   
  36.             $this->writelogs($success);  
  37.             echo 'OK';  
  38.             return true;  
  39.     }   
  40.       
  41.     //记录日志 txt  
  42.     public function writelogs($data) {   
  43.         $base_path = rtrim($_SERVER['DOCUMENT_ROOT'],'/')."/logs/";   
  44.         $myfile = $base_path  . "time_log.txt";  
  45.         $times = date('Y-m-d H:i:s', time());   
  46.         //$string = $times ."=========>" $data."\n";   
  47.         $string = $times.'======>'.$data."\n\r";   
  48.         file_put_contents($myfile$string , FILE_APPEND);  
  49.     }     
0 0
原创粉丝点击