Re: HTML in Download data?

From: Date: Fri, 24 Sep 2004 11:16:42 +0000
Subject: Re: HTML in Download data?
Groups: php.general 
Request: Send a blank email to php-general+get-197768@lists.php.net to get a copy of this message
Thomas Hochstetter wrote:
Hi there, I am (again) trying to download a file from off the server and force it to use the download dialog box. I have been trying pclzip.lib for compression and used my own headers (as depicted below). This version did zip nicely and the files were intact in the tmp folder. But once I used the headers it mixed the html code into the resulting zip file. I know I must not mix the my html and the zip data . but why is this happening? Then I have used PEAR's HTTP_DOWNLOAD. The result: the exact same problem. HTML is mixed with the data coming from the headers. We have used ob_start() ( with gzip handlers), which I have taken out now, but the problem is still the same. So that cannot be the problem? Why on earth does it mix the html with the data? I do not include any html files. Below are the two variations. The function 'PackAndSend' is called before any output has taken place. [1] // The headers // header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=$name" );
$name is not defined. I guess there is some code above these lines.
header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0,pre-check=0"); header("Pragma: public"); // The zipping // $mime = mime_content_type("files/papers/$_GET[file]");
Do you realize this is unsafe? I can pass you any filename, including ../../config.php
$filePath = realpath( "tmp/zips/". substr( md5( $_GET["file"] ), 0, 5 ) .".zip" ); $zip = new PclZip( $filePath ); $zip->create( "files/papers/$_GET[file]", "[ICT2005] Review Resources/Paper ID [$_GET[file]]", "files/papers/$_GET[file]" ); // reading the resulting zip file // @readfile( "files/papers/$_GET[file]" ); // destroying the copy // unlink( $filePath ); [2] require_once( 'HTTP/Download.php' );
                                    $dl = &new HTTP_Download();
$dl->setFile('files/papers/'.$_GET['file']); $dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $_GET['file']); $dl->setContentType('application/x-gzip'); $dl->send(); Also, if I use the headers (as above in [1]) with a normal file, it has got the neck of working fine on my machine (XP Pro, IE6, Apache 1.3, PHP4.3.2) but not on the server (Debian, IE6, Apache 1.3, PHP4.02).
What html does it output? It has to be somewhere, php is not making it up. Remember that you cannot send both html and the content of the zipfile in the same *REQUEST*. It does not help that you separate them in your output. HTH

« previous php.general (#197768) next »