我試圖將圖像從遠程服務器用下面的代碼複製:複製的圖像從一個服務器到另一個使用PHP
$src = "http://www.imagelocation.com/image.jpg";
$dest = "/server/location/upload/";
file_put_contents($dest, file_get_contents($src));
不幸的是我不斷收到以下錯誤:
Warning: file_put_contents(/server/location/upload/) [function.file-put-contents]: failed to open stream: Is a directory in /server/location/myscript.php on line 220
你有什麼想法如何解決這個問題?
完美,這個例子確實也有幫助。謝謝!另一方面,如果複製成功或沒有成功,我將如何解決? – David 2012-02-05 20:25:47
使用$ check = file_put_contents($ dest,file_get_contents($ src)); 並查看$ check的值。 http://php.net/manual/en/function.file-put-contents.php說: 該函數返回寫入文件的字節數,或失敗時返回FALSE。 – Daan 2012-02-05 20:30:31