PHP Download statt anzeigen

Hallo !

Ich habe einen Link

HTML:
<a href="pfad/bild.jpg">Bild</a>
Nun wird mir das Bild angezeigt und ich möchte es runterladen. Dafür habe ich folgendes

HTML:
<a href="download.php?file=pfad/bild.jpg">Download</a>
Ich möchte, dass das Bild gespeichert werden kann, wenn man auf Download klickt.

Meine download.php sieht wie folgt aus :

PHP:
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Pragma: no-cache");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Content-type: application/force-download");  
    header("Content-Disposition: filename=".$_GET['file']."");
Nun wird der Download gespeichert, aber das Bild hat nur 2 Byte. Ideen ?
 
PHP:
header("Content-Length: ".filesize("BILD.ENDUNG"));

häng das mal noch ran an deinen header ;)
 
Hi !

Immer noch nichts. Ich übergebe immer den kompletten Pfad zur Datei, wie

HTML:
<a href="download.php?file=bilder/große/kunden/bild.jpg">Download</a>

ich habe nun

PHP:
header("Content-Length: ".filesize($_GET['file']));

also komplett :

PHP:
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Pragma: no-cache");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Content-type: application/force-download");  
    header("Content-Length: ".filesize($_GET['file']));  
    header("Content-Disposition: filename=".$_GET['file']."");

Nun steht da immer noch 0 Bytes !
 
Das Bild gibst du aber nachdem du die headers gesendet hast auch aus oder?

PHP:
// header stuff
echo file_get_contents($_GET['file']);
 
Meine download.php sieht wie folgt aus :

PHP:
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Pragma: no-cache");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Content-type: application/force-download");  
    header("Content-Disposition: filename=".$_GET['file']."");

LFI & RFI

Nun wird der Download gespeichert, aber das Bild hat nur 2 Byte. Ideen ?
PHP: readfile - Manual

Micha
 
nenn mich paranoid, aber $_GET['whatever'] ohne prüfung raus zugeben könnte IMHO leichte sicherheitslücken bergen
 
Zurück
Oben