Portál AbcLinuxu, 16. prosince 2025 02:26
$fileName = $prihlaska[0]['prihlaska'].".pdf";
$fileDir = "/home/me/pdf/";
$fileString=$fileDir.'/'.$fileName;
// translate file name properly for Internet Explorer.
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")){
$fileName = preg_replace('/\./', '%2e', $fileName, substr_count($fileName, '.') - 1);
}
if(!$fdl=@fopen($fileString,'rb')){
die("Cannot Open File!");
} else {
header("Cache-Control: ");// leave blank to avoid IE errors
header("Pragma: ");// leave blank to avoid IE errors
header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=\"".$fileName."\"");
header("Content-length:".(string)(filesize($fileString)));
header("Content-Transfer-Encoding: binary");
sleep(1);
fpassthru($fdl);
}
header("Pragma: public");
header("Expires: 0");
header("Pragma: no-cache");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header('Content-disposition: attachment; filename=' . basename($fileName));
header("Content-Type: application/pdf");
header("Content-Transfer-Encoding: binary");
header('Content-Length: ' . filesize($filename));
function send_PDF_file_to_browser($file)
{
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Type: application/pdf");
//header("Content-Disposition: attachment; filename=".basename($file).";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($file));
readfile($file);
}
A jeste je mozne se inspirovat zde :)
Adobe-Win7 nadava, ze je bud spatny typ nebo je poskozeny. Tento soubor je mensi nez original na disku.To je klíčová informace. Ten soubor se ze serveru nepošlete celý, obrázky jsou v něm zřejmě až na konci, proto se nezobrazí. Mimochodem, 4 hlavičky
Content-Type jsou nesmysl, hlavička Content-Transfer-Encoding není součástí standardu HTTP, hlavička Expires s hodnotou 0 taky není zrovna košer ( i když by si s ní klient měl poradit).
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.