Jump to content

[SOLVED] Hiding Direct Download Links -- Browser freezes!!!!!!!!!


validkeys

Recommended Posts

I have a download script that enables me to allow users to download music from my site with out knowing the exact url of the song.

 

Here is the main part of the scrpt:

 

    $filesize = filesize($realDLfolder.$path.$filename);
$xtype="audio/mpeg";

$fp=@fopen($realDLfolder.$path.$filename,"rb");


if ($fp) {
// Create the headers used for downloading the file
header("Content-Transfer-Encoding: binary");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: ".$xtype);
header("Accept-Ranges: bytes");				
header("Content-Disposition: attachment; filename=\"".$filename."\";");
header("Content-Length: ".$filesize);	
// Actually start downloading the file


while (!feof($fp)) { 
   		echo(@fgets($fp, 4096)); } 

fclose ($fp);
}

 

Whenever I now click on the link, my entire browser freezes and I have to force quit. What am I doing wrong? Does it have to do with the size of the files?

 

Thanks

Try this version (works great for me):

 

<?php

$full_name = $realDLfolder.$path.$filename;
$xtype="audio/mpeg";

// required for IE, otherwise Content-disposition is ignored
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: $xtype");
header("Content-Disposition: attachment; filename=\"".basename($full_name)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($full_name));
@readfile($full_name);
exit;

?>

 

 

Orio.

thanks so much! I guess the problem was that I was using Ajax to request the download.php file and it was having problems with returning the xhtml response.

 

I just hardcoded in a link to download.php?...

 

and it worked fine.

 

thanks so much

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.