我正在尝试编写一个可以在本地保存多个PDF文件的php函数,有些下载得很好,但其他文件似乎被截断,无法用PDF阅读器进行操作。
实际的保存功能由定位路径的函数调用:
function findURLs(){
// do something to find URLs & next print them
while(*some condition*){
savePDF($url,$id);
}
}
这是实际功能:
function savePDF($url,$id){
$path="../downloads/".$id.".pdf";
try {
$data = file_get_contents($url);
$handle = fopen($path, "w");
fwrite($handle, $data);
fclose($handle);
return true;
echo "file saved";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
return false;
}
有什么建议吗?它可能是远程文件大小?
谢谢!
* P.S。我希望将文件保存到服务器(我的localhost),而不是通过浏览器下载文件..