Results 1 to 3 of 3
Hi, my problem is with some file extension like .cab and .7z, when I try to download them from server I get a lot of nonsense instead, the files never ...
- 02-23-2008 #1
Problems with certain files
Hi, my problem is with some file extension like .cab and .7z, when I try to download them from server I get a lot of nonsense instead, the files never download. All other files like .mp3 and .txt work fine.
Cant find any entry similar to my problem in Google
My server
Ubuntu 6.06LTS with LAMP
Thank you in advance
- 02-23-2008 #2Linux User
- Join Date
- Jan 2006
- Posts
- 414
This sounds like a browser problem, not a server problem. The browser is trying to open the file instead of downloading it, just right click on the file and 'save as', or if you want to force the download, use a php script something like:
save it as download.php and just go to :Code:<?php $filename = $_GET['file']; $file_extension = strtolower(substr(strrchr($filename,'.'),1)); if (($filename == '') || (!file_exists($filename))) { echo 'Invalid Filename'; exit; } switch($file_extension) { case "pdf": $ctype="application/pdf"; break; case "zip": $ctype="application/zip"; break; case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpg": $ctype="image/jpg"; break; default: $ctype="application/force-download"; } 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: $ctype"); header("Content-Transfer-Encoding: binary"); header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" ); header("Content-Length: ".filesize($filename)); readfile("$filename"); exit(); ?>
download.php?file=myfile.cabLast edited by devils casper; 02-23-2008 at 08:07 AM.
- 02-23-2008 #3
Thank you for reply
Actually I have tested both in FireFox and IE, Linux and Windows. Thats why I thought it was a web server problem, I will try your solution.
Thank you.


Reply With Quote