L4DD13
February 23, 2012, 11:14am
1
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
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.
L4DD13
February 23, 2012, 11:56am
3
Hi,
Thanks @StarLion , I tried your code but im still receiving corrupt files.
I also tried it with relative paths.
This is my 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');
readfile( self::EXPORT_DIRECTORY . basename( /* absolute path to tar location */ ) );
unlink( self::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
L4DD13
February 23, 2012, 12:00pm
4
Hi,
Ignore my previous post, your code does work.
It must be something prior to the download, etc which is causing the issue.
Cheers.
L4DD13
February 23, 2012, 12:29pm
5
There was a legacy script which was causing issues.
I ‘solved’ the issue using output buffering.