0
文件保存在PHP我這是應該將文件保存到我的服務器的功能,該功能需要兩個參數文件的URL並在其將要與數據庫中保存的文件名通過URL
function saveFile($url, $filename){
$location = "http://138.90.30.311/docs/";
$ext = pathinfo($url, PATHINFO_EXTENSION);
$file_path = $location.''.$filename.'.'.$ext;
$ch = curl_init($url);
$fp = fopen($file_path, 'wb'); //Error here (line 16)
curl_setopt($ch, CURLOPT_FILE, $fp); //Error here (line 17)
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
傳遞的參數
例子是
filename = 14426
url = http://u.goal.com/269000/269085_hp_thumb.jpg
我得到它的工作一次,但它似乎並沒有保存該文件不再和我得到3個錯誤
Warning: fopen(http://138.90.30.311/docs/14426.jpg) [function.fopen]: failed to open stream: HTTP wrapper does not support writeable connections in C:\wamp\www\functions.php on line 16
Warning: curl_setopt(): supplied argument is not a valid File-Handle resource in C:\wamp\www\functions.php on line 17
之後第二個錯誤,我得到了很多的垃圾回顯到瀏覽器
Warning: fclose() expects parameter 1 to be resource, boolean given in C:\wamp\www\functions.php on line 21
我想要做的是取得一個由url傳入的文件並保存在那個位置 – Amanni 2013-04-03 20:42:11
如果要保存的位置在同一臺服務器上運行,只需給出目錄路徑,而不是'http://...'。如果沒有,你需要使用類似FTP的東西來上傳。 – IMSoP 2013-04-03 20:49:28
我試過了,仍然得到相同的錯誤,我現在已經將該文件夾的所有權更改爲管理員,但仍然是相同的錯誤。 – Amanni 2013-04-03 21:10:49