Bilder downloaden

Snowowl

Erfahrenes Mitglied
Hi,
habe mal wieder ein Problem. Habe folgendes Script:

(downlaod.php)
PHP:
<?php 
function download($file , $name) { 
    $size = filesize($file); 
    header("Content-type: application/octet-stream"); 
    header("Content-disposition: attachment; filename=".$name); 
    header("Content-Length: ".$size); 
    header("Pragma: no-cache"); 
    header("Expires: 0"); 
    readfile($file); 
} 
download("images/$file"); 
?>
Dies soll bewirken, dass wenn ich die download.php mit dem PHP tag ?file=1.jpg öffne, dass das Bild 1.jpg aus dem Ordner images gedownloaded wird.
doch dann kommt der Error:

Warning: Missing argument 2 for download() in /mnt/sda/home/u0012516124/public_html/download.php on line 2

Warning: filesize(): Stat failed for images/1.jpg (errno=2 - No such file or directory) in /mnt/sda/home/u0012516124/public_html/download.php on line 3

Warning: Cannot modify header information - headers already sent by (output started at /mnt/sda/home/u0012516124/public_html/download.php:2) in /mnt/sda/home/u0012516124/public_html/download.php on line 4

Warning: Cannot modify header information - headers already sent by (output started at /mnt/sda/home/u0012516124/public_html/download.php:2) in /mnt/sda/home/u0012516124/public_html/download.php on line 5

Warning: Cannot modify header information - headers already sent by (output started at /mnt/sda/home/u0012516124/public_html/download.php:2) in /mnt/sda/home/u0012516124/public_html/download.php on line 6

Warning: Cannot modify header information - headers already sent by (output started at /mnt/sda/home/u0012516124/public_html/download.php:2) in /mnt/sda/home/u0012516124/public_html/download.php on line 7

Warning: Cannot modify header information - headers already sent by (output started at /mnt/sda/home/u0012516124/public_html/download.php:2) in /mnt/sda/home/u0012516124/public_html/download.php on line 8

Warning: readfile(images/1.jpg): failed to open stream: No such file or directory in /mnt/sda/home/u0012516124/public_html/download.php on line 9

Was mache ich falsch?
Vielen Dank im Vorraus,
Niklas
 
Wie wärs damit:
PHP:
<?php 
function download($file) { 
    $size = filesize($file); 
    header("Content-type: application/octet-stream"); 
    header("Content-disposition: attachment; filename=".$file); 
    header("Content-Length: ".$size); 
    header("Pragma: no-cache"); 
    header("Expires: 0"); 
    readfile($file); 
} 
$file = "datei.ext";
$datei = "images/". $file;
download($datei); 
?>

Ich würde allerdings noch ein paar Prüfabfragen einbauen, denn so ist es etwas unsicher ;)
 
Zurück