SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2008
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Forcing download of tar.gz results in corrupt file

    Hi,

    I've tried various different combinations of headers force the download of a tar.gz file.
    I've also tried copying the file and forcing the download of the copied file after opening and closing it.

    Every attempt has resulted in a corrupt file.

    Currently, i'm running the scripts locally, so i've checked the actual file and opens fine, but like i said, the downloaded version is always corrupt.

    Has anyone got any working header combinations?

    Cheers,
    Michael

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    header('Content-disposition: attachment; filename=yourfile.tar.gz');
    header('Content-type: application/x-gzip');
    readfile('yourfile.tar.gz');

    the tar type shouldnt matter; the external wrapper is a gzip.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2008
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks @StarLion , I tried your code but im still receiving corrupt files.
    I also tried it with relative paths.


    This is my code:

    PHP Code:
    $tarfile = new Archive_Tar/* absolute path to tar location */ );
    if( 
    $tarfile->create$files ) )
    {
        
    header('Content-disposition: attachment; filename=' basename/* absolute path to tar location */ ) );
        
    header('Content-type: application/x-gzip');
        
    readfileself::EXPORT_DIRECTORY basename/* absolute path to tar location */ ) );
        
    unlinkself::EXPORT_DIRECTORY basename/* absolute path to tar location */ ) );
    } else {
        throw new 
    Exception'Failed to create archive' );

    I've tried it without the unlink, but that made no difference.

    Cheers

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2008
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Ignore my previous post, your code does work.
    It must be something prior to the download, etc which is causing the issue.

    Cheers.

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2008
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There was a legacy script which was causing issues.
    I 'solved' the issue using output buffering.


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
  •