Hi there,
Long story short. I've specified this coding in my download.php file

header("Content-disposition: attachment; filename=$filename");
  header("Content-type: application/octet-stream");
  readfile("$namee/$downloads/$filename");

Problem is, when the script downloads a GIF file, and when I save it onto my PC I can't open it using IrfanView or any other ImageViewer. I have a feeling it's the way I specified the "Content-type:" bit

Any ideas?

Thanks

    <?php
    // Added for Register Globals off default in newer versions of PHP
    $file = $_GET['file'];
    
    // Generate an error if no file is specified
    if( $file == "" ) {
      echo "<html><title>No File Specified</title><body><h3>ERROR: Download file NOT SPECIFIED.</h3></body></html>";
      exit();
    }    
    
    // Confirm that the file exists
    if (!is_file($file)) {
        echo"<html><title>File Not Found</title><body><h3>Error: File not found</h3></body></html>";
        exit();
        }
    
    // Required for some versions of IE if compression is turned on at the server level
    if(ini_get('zlib.output_compression')) {
      ini_set('zlib.output_compression', 'Off');
    }
    
    /* Gather info about the file */
    // Get the size of the file
    $len = filesize($file);
    // Re-variablize the filename for later use to avoid confusion
    $filename = basename($file);
    // extract the file extension
    $file_extension = strtolower(substr(strrchr($file,"."),1));        
    
    // This will set the Content-Type to the appropriate setting for various types of media files
    // Add a new case for any additional media files you want to allow to be downloaded
    switch( $file_extension ) {
        case "pdf": $ctype="application/pdf"; break;
        case "exe": $ctype="application/octet-stream"; break;
        case "zip": $ctype="application/zip"; break;
        case "doc": $ctype="application/msword"; break;
        case "xls": $ctype="application/vnd.ms-excel"; break;
        case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
        case "gif": $ctype="image/gif"; break;
        case "png": $ctype="image/png"; break;
        case "jpeg":
        case "jpg": $ctype="image/jpg"; break;
        case "mp3": $ctype="audio/mpeg"; break;
        case "wav": $ctype="audio/x-wav"; break;
        case "mpeg":
        case "mpg":
        case "mpe": $ctype="video/mpeg"; break;
        case "mov": $ctype="video/quicktime"; break;
        case "avi": $ctype="video/x-msvideo"; break;
    
      // Next up is to add a bit of security.  Since the force-download could be used to download ANY file you'll want to exclude any extensions that might contain sensitive information.  Add a new case statement for any additional filetypes you wish to exclude.
        case "php":
        case "asp":
        case "htm":
        case "html":
        case "htaccess":
        case "htpasswd":
        case "txt": die("<h3>Cannot be used for ". $file_extension ." files!</h3>"); break;
        default: $ctype="application/force-download";
    }
    
    header("Pragma: public"); // required
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private",false); // required for certain browsers
    header("Content-Type: $ctype");
    // Extra (escaped) quotes added to allow for filenames that include a space.
    header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".filesize($filename));
    readfile("$filename");
    exit();
    ?>
    

      I cannot thank you enough :eek:
      Promote that man!
      Thanks alot

        Write a Reply...