DZone Forums
Go Back   DZone Forums > Community > Languages & Frameworks > PHP
Reload this Page force download
Notices
Reply
 
LinkBack Thread Tools Display Modes
  (#1 (permalink)) Old
Member
 
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Apr 2008
Default force download - 04-09-2008, 01:43 AM

I've tried the force download script from your article (PHP Force Download - Keep Up With What's Going Down | PHP Zone) 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 file are in the photos folder. The file(s) are images, IMG1.jpg, IMG2.jpg, etc. So, the link users click is like download.php?filename=IMG1.jpg.

Your help is much appreciated.

##code
$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;
Reply With Quote
  (#2 (permalink)) Old
Member
 
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Join Date: Sep 2008
Default Re: force download - 03-27-2009, 05:16 PM

I copied your script into a php file on my server and it worked without a problem. The only thing I changed was the folder path ("/photos/lrg/" to "/phptesting/force_download/") to reflect the different folder structure on my server.

The only thing I can think that would make this script perform the way you described is if the code that you posted is the entire contents of the file. If this is the case, the file is nothing but a text file and your PHP server will do nothing with it except send it directly to the browser. PHP code is meaningless to the server unless it is enclosed it in PHP tags.
PHP Code:
<?php
// Script goes here
?>
I'm convinced this is what happened because, on my computer, the PHP file is 603 bytes, which is pretty close to 500.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Download Sources of CDT 5.0.1 lego123 Eclipse 0 10-13-2008 04:04 AM
Download links in e-mails (RefCardz) j.berger Feedback 2 07-02-2008 12:05 PM
How download files with servlet? sreenivas.angadi Java 0 05-07-2008 06:28 AM


Copyright 1997-2009, DZone, Inc.
vBulletin Skin developed by: vBStyles.com