我有一个应该将文件保存到我的服务器的函数,该函数需要两个参数,文件 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