validkeys Posted March 20, 2007 Share Posted March 20, 2007 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 Link to comment https://forums.phpfreaks.com/topic/43582-solved-hiding-direct-download-links-browser-freezes/ Share on other sites More sharing options...
suzzane2020 Posted March 20, 2007 Share Posted March 20, 2007 this cud happen if ur file function syntax is not correct, i'd say try commenting parts of the script and executing ..helps u pinpoint the error causing section Link to comment https://forums.phpfreaks.com/topic/43582-solved-hiding-direct-download-links-browser-freezes/#findComment-211667 Share on other sites More sharing options...
validkeys Posted March 20, 2007 Author Share Posted March 20, 2007 i actually had tried that and this seemed to be the part giving me problems while (!feof($fp)) { echo(@fgets($fp, 4096)); } fclose ($fp); Link to comment https://forums.phpfreaks.com/topic/43582-solved-hiding-direct-download-links-browser-freezes/#findComment-211670 Share on other sites More sharing options...
suzzane2020 Posted March 20, 2007 Share Posted March 20, 2007 have 2 options try gettin the content by concatenation $data=$data . fread($fp) or change the size parameter to $fp, filesize($fp)) Link to comment https://forums.phpfreaks.com/topic/43582-solved-hiding-direct-download-links-browser-freezes/#findComment-211673 Share on other sites More sharing options...
validkeys Posted March 21, 2007 Author Share Posted March 21, 2007 I tried both things that you recommended but It didnt seem to change anything. I dont know what the problem is! Link to comment https://forums.phpfreaks.com/topic/43582-solved-hiding-direct-download-links-browser-freezes/#findComment-211939 Share on other sites More sharing options...
Orio Posted March 21, 2007 Share Posted March 21, 2007 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. Link to comment https://forums.phpfreaks.com/topic/43582-solved-hiding-direct-download-links-browser-freezes/#findComment-211948 Share on other sites More sharing options...
validkeys Posted March 21, 2007 Author Share Posted March 21, 2007 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 Link to comment https://forums.phpfreaks.com/topic/43582-solved-hiding-direct-download-links-browser-freezes/#findComment-211957 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.