img download / counter viewing(back to index)Hello,
zwo questions:
1. ikue has under the following link http://blog.ikue.de/fb.php/image/P1010050.jpg/ a link to download the picture / img file - how works it? and: can I download a different file (greater file size and resolution)?
2. a counter how often a picture / image has been viewed?
Thanks
Martin
posted by
Martin on 22 Jun 06 at 8:51 AM
1) ikue has written this nice and nasty function himself but is willing to share it with you ;) so, just some details about it - the easiest solution for you is to create a separate file which has the task to modify the mime type received by the browser, telling it that it would be a file to be downloaded & saved instead of being displayed.
The magic code then goes like this:
(downloader.php)
<?php
//Gather relevent info about file
$len = filesize($directory.$file);
$file_extension = strtolower(substr(strrchr($file,"."),1));
//This will set the Content-Type to the appropriate setting for the file
switch($file_extension) {
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
case "3gp": $ctype="video/3gpp"; break;
default:showerror("File requested for encrypted display has no valid extension.");
}
//Begin writing headers
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
//Use the switch-generated Content-Type
header("Content-Type: $ctype");
//Force the download
$filename = strtolower(substr(strrchr($file,"/"),1));
header("Content-Disposition: attachment; filename=".$filename.";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$len);
@readfile($directory.$file);
exit;
?>
This is directly copied from my own source code, you have to rewrite some things about the variables which have to be given as a parameter to downloader.php
posted by
ikue on 25 Jun 06 at 5:28 AM