Current location: Hot Scripts Forums » Programming Languages » PHP » How to force download dialog box instead of download software


How to force download dialog box instead of download software

Reply
  #1 (permalink)  
Old 06-06-08, 03:36 PM
iampick iampick is offline
New Member
 
Join Date: Jun 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
How to force download dialog box instead of download software

Hi,

Many Download software (MD, IDM, Flashget, etc ...) are mass download software
It make many many connections to my server. So I want to know how to force download dialog box ( save as, open ) instead of download software promt.

If you use Hotmail you will see that attached file can't download with download software and Hotmail force user to use normal download dialog box

I tried to coding with php-header .. but it still not work.
Reply With Quote
  #2 (permalink)  
Old 06-06-08, 06:08 PM
Kelvin Kelvin is offline
Newbie Coder
 
Join Date: Apr 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Trophee

I'm assuming you basically want to stop people from hammering your server? i.e. limiting the number of requests any person can make.

Many sites stream the downloads directly via PHP scripts, since PHP scripts are singled threaded so its impossible for the users download manager to start downloading in multiple chunks

PHP Code:

<?    
    $filename 
$_GET["filename"];
    
$buffer file_get_contents($filename);

    
/* Force download dialog... */
    
header("Content-Type: application/force-download");
    
header("Content-Type: application/octet-stream");
    
header("Content-Type: application/download");

    
/* Don't allow caching... */
    
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

    
/* Set data type, size and filename */
    
header("Content-Type: application/octet-stream");
    
header("Content-Transfer-Encoding: binary");
    
header("Content-Length: " strlen($buffer));
    
header("Content-Disposition: attachment; filename=$filename");

    
/* Send our file... */
    
echo $buffer
?>
You would then link to this file, something like http://yourDomain.com/download.php?filename=xxx.zip and it would send the xxx.zip file.

WARNING - be very careful doing this though, do a lot of sanitizing on the filename value, be sure to strip slashes, only allow predefined files to be downloaded.

NOTE - Its VERY important that you do not send any other output, only data read from the file should be echo'd out,

I've not fully tested this code - personally I use something a little more simplistic -

PHP Code:

<?    
    $filename 
"/home/YOURFILE";
    
$buffer file_get_contents($filename);
    
header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    
header ("Content-Type: application/octet-stream");
    
header ("Content-Length: " strlen($buffer));
    
header ("Content-Disposition: attachment; filename=$filename");
    echo 
$buffer;    
?>

Alternatively you could take measures directly via Apache - http://www.webhostgear.com/279.html

I Hope this helps.

Last edited by Kelvin; 06-06-08 at 06:14 PM.
Reply With Quote
  #3 (permalink)  
Old 06-01-09, 05:49 PM
acheo acheo is offline
New Member
 
Join Date: Jun 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Kevin,

Do you know how to force download of several files at the same time. I want my users to select their files and then, to download them with one click.

thanks
Reply With Quote
  #4 (permalink)  
Old 06-01-09, 05:53 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Take the selected files, tar or zip them, then use the offered code to deliver the tar/zip file.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programmer Needed (Forums Software) LandonCowling Job Offers & Assistance 2 01-17-05 05:02 AM


All times are GMT -5. The time now is 07:45 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.