'ello all.

I am using HTTP_Download to simplify file downloading and to use throttling, resuming, etc ...

Problem is, I cannot seem to get files to download properly. They download all the way, but applications become corrupt. Images and plain text download fine.

I can access the files via FTP, download them and open them fine.

Here is the code I am using ... any insight as to what may be wrong would be great.

/** if file is zipped, change content type **/
          preg_match("#^.*\.([A-Z0-9]+)$#i", $result['localname'], $matches);
          $ext = strtolower($matches[1]);
          if($ext == 'zip') $result['mimetype'] = 'application/zip';
          /** guest file, let DL **/
          $dl = new HTTP_Download();
          $dl->setFile(PUB_DIR . DS . $result['localname']);
          $dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $result['outputname']);
          /** if userID == 0 **/
          if(isset($_SESSION['userid']) && $_SESSION['userid'] == 0){
            $dl->setBufferSize(300 * 1024); // 300 KB
            $dl->setThrottleDelay(1);   // 1 sec
          }
          $dl->setContentType($result['mimetype']);
          $dl->send();

Thanks!

    7 days later

    Ok, so I moved away from HTTP_Download to see what would happen.

    Using the following code I still get the same results as using HTTP_Download ...

    Archives, images and text download ... executables and PDF's corrupt, but can be downloaded fine from FTP.

    Does anyone see anything wrong with this code?

    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".$result['filesize']);
    header('Content-Disposition: ' . 'attachement' . '; filename="' . $result['outputname'] . '"');
    header("Content-type: ".$result['mimetype']);
    
    if(is_file(PUB_DIR . DS . $result['localname'])) readfile(PUB_DIR . DS . $result['localname']);
    else die('No file exists.');

    TIA!!!

      Write a Reply...