file_put_contents() failed to open stream: Permission denied 問題解決


很長時間沒有寫PHP了,今天突然有個需求要寫一個保存文件的功能。

function downloadFile( $url , $savePath = '' )
{
    $fileName = getUrlFileExt( $url );
    $fileName = rand(0,1000). '.' . $fileName ;
    $file = file_get_contents ( $url );
    file_put_contents ( $savePath . '/' . $fileName , $file );
    return $fileName ;
}

 

調用downloadFile(  "http://www.xxx.com"  ,  "/bak"  );

怎么都不行,一直提示file_put_contents() failed to open stream: Permission denied

后面把文件夾權限也加上還是不行,郁悶了。

最后突然想到地址不應該是相對的哦。

改為downloadFile(  "http://www.xxx.com"  ,  rtrim($_SERVER['DOCUMENT_ROOT'],'/')."/bak"  ); 搞定了,哎要是換成以前肯定一下就想到了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM