$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 is e.g:
https://bip.wzp.pl/attachments/28172_Statut Województwa
Zachodniopomorskiego.pdf
When I trying it browser, a pdf document displayes properly.
But downloaded file via PHP, it is always corrupted.
EDIT
I checked $data content. It has front page html :/
It strange putting $source_path to browser returns pdf
Seems like you try to download a PDF, try saving it as a binary file using: