Find the answer to your Linux question:
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! ls354's Avatar
    Join Date
    May 2006
    Location
    Cloud 9
    Posts
    97

    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

  2. #2
    Linux 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:
    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();
    
    ?>
    save it as download.php and just go to :
    download.php?file=myfile.cab
    Last edited by devils casper; 02-23-2008 at 08:07 AM.

  3. #3
    Just Joined! ls354's Avatar
    Join Date
    May 2006
    Location
    Cloud 9
    Posts
    97

    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.

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •