•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 402,014 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,375 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 916 | Replies: 5
![]() |
•
•
Join Date: Mar 2008
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
I've tried the following force download script and for the life of me I can't get it to download the file. I get the download dialog pop-up, but the file size is only around 500 bytes. I think it is the pathing. I've tried absolute and relative paths for readfile and filesize. The thumbnail page and download.php file are in the photos folder. The file(s) I want to download are images, IMG1.jpg, IMG2.jpg, etc. So, the link users click to download is: download.php?filename=IMG1.jpg.
Your help is much appreciated.
Your help is much appreciated.
PHP Syntax (Toggle Plain Text)
$filename = $_GET['filename']; $path = $_SERVER['DOCUMENT_ROOT']."/photos/lrg/"; #$path = "lrg/"; $fullpath = $path.$filename; if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header("Content-Type: image/jpg"); header("Content-Disposition: attachment; filename=\"".$filename."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($fullpath)); readfile($fullpath); exit;
•
•
Join Date: Aug 2005
Location: Cologne, Germany
Posts: 106
Reputation:
Rep Power: 4
Solved Threads: 9
Use
to add the size of your image as well. It then should work.
header("Content-Length: ".$filesize($fullpath));•
•
Join Date: Mar 2008
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
Use
to add the size of your image as well. It then should work.header("Content-Length: ".$filesize($fullpath));
Thanks, but that didn't work. The filesize in the pop-up dialog is now 139 bytes.
php Syntax (Toggle Plain Text)
<? $filename = $_SERVER['DOCUMENT_ROOT']."/photos/lrg/".$_GET['filename']; //$filename="picture0.jpg"; if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header("Content-Type: image/jpeg"); header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); readfile("$filename"); exit(); ?>
Last edited by peter_budo : Apr 29th, 2008 at 8:42 am. Reason: Keep It Organized - please use [code] tags
•
•
Join Date: Mar 2008
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
I decided to browser directly to one of the 'lrg' photos and see if it came up - it didn't. So, I looked in the folder via FTP and they are there. After staring at them for a few minutes I noticed that the JPG extension had capital letters. When I browsed and ran the script I was using lower case letters. The larger photos were upper case because they were the original photos from the camera and the thumbnails are the ones I created.
I did try everyones suggestions before figuring out the little detail of letter cases. Thanks for your help.
The code I am using below works.
I did try everyones suggestions before figuring out the little detail of letter cases. Thanks for your help.
The code I am using below works.
PHP Syntax (Toggle Plain Text)
$filename = $_GET['filename']; $path = $_SERVER['DOCUMENT_ROOT']."/photos/lrg/"; $fullpath = $path.$filename; // required for IE, otherwise Content-disposition is ignored if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); header("Pragma: public"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // required for certain browsers header("Content-Transfer-Encoding: binary"); header("Content-Type: image/jpg"); header('Content-Disposition: attachment; filename="'.$filename.'"'); header("Content-Length: ".filesize($fullpath)); readfile($fullpath); exit;
Last edited by spiderling : Apr 28th, 2008 at 12:42 pm.
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- hjt log- download. trojan detected (Viruses, Spyware and other Nasties)
- PHP in a html page? (PHP)
- Save Target as... (JavaScript / DHTML / AJAX)
- not view just download (PHP)
- fitting g force graphic card wont work(athlon m/b) (Monitors, Displays and Video Cards)
- html table to .csv (HTML and CSS)
Other Threads in the PHP Forum
- Previous Thread: Final Year Project Ideas
- Next Thread: Admin login problem


Linear Mode