$source_path = 'https://bip.wzp.pl/attachments/' . $filename;
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Content-type: application/pdf",
)
);
$context = stream_context_create($opts);
$data = file_get_contents($source_path, false, $context);
if(($handle = fopen($dest_path, "w"))) {
fwrite($handle, $data);
fclose($handle);
return $filename_converted;
}
例如$source_path
:
https://bip.wzp.pl/attachments/28172_Statut 沃耶沃兹特瓦 Zachodniopomorskiego.pdf
当我尝试浏览器时,pdf文档显示正确。
但是通过PHP下载的文件,它总是被损坏。
编辑
我检查了$data
内容。它有首页html :/奇怪的是将$source_path
放入浏览器返回pdf
似乎您尝试下载 PDF,请尝试使用以下方法将其另存为二进制文件:
fopen($dest_path, "wb")