php download problem.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Got the following to pop a download dialogue:

$p = explode('.', $file);
    $pc = count($p);

    //send headers
    if(($pc > 1) AND isset($mimetype[$p[$pc - 1]]))
        //display file inside browser
        header("Content-type: " . $mimetype[$p[$pc - 1]] . "\n");
        //force download dialog
    header("Content-type: application/octet-stream\r\n");
    header("Content-disposition: attachment;
    header("Content-transfer-encoding: binary\r\n");
    header("Content-length: " . filesize($path) . "\r\n");
    $fp=fopen($path, 'rb');

Download dialogue pops just fine and the file gets saved.  However,
without fail, the file is 2 bytes larger than the source file.  I'm
stumped.  Any ideas?



Re: php download problem.

Quoted text here. Click to load it

 Leading or trailing space in the PHP file?

 Have you put the resulting file through a hex editor to find what those two
bytes are? (I think it's a good bet they're \r\n)

 You also don't need to put \r\n in calls to header() - this may even be
causing problems.

Andy Hassall :: :: :: disk and FTP usage analysis tool

Re: php download problem.

Yep, removed the d**n \r\n stuff from the headers and, lo and behold,
the files are EXACTLY the same size.   ARGGGHHHH!!!  Thanks for that AH
!!!   :-o


Site Timeline