SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    header download only partial

    Hello,

    I'm not sure whether this should go in here or the PHP section. Mod please feel free to move it.

    I have a strange problem.

    I've got a folder in my public_html directory that contains some zip files.

    To block direct access to these files, I have placed a htaccess with this content

    Code:
    Order Allow,Deny
    Deny from all
    I then have a php script where users can download files. This script contains this code:

    Code:
                         // Set headers
                         header("Cache-Control: public");
                         header("Content-Description: File Transfer");
                         header("Content-Disposition: attachment; filename=".basename($file)."");
                         header("Content-Type: application/zip");
                         header("Content-Transfer-Encoding: binary");
                                             header('Content-Length: ' . filesize($file)); // added this line as per suggestion
                         // Read the file from disk
                         readfile($file);
    The problem is, when I have the htaccess. The zip is only being downloaded partially. Without the htaccess it downloads fully. Any idea why this is happening?

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,143
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Are you using a URL for the value of $file or the system path to the file? I ask because if you using a URL, the htaccess would like affect it, however, if you use C:/mypath/myfile.zip (or the linux variant, /home/myuser/public_html/myfolder/myfile.zip), htaccess shouldn't play a role in accessing the file.


Bookmarks

Posting Permissions

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