php download problem.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kevinm3574

    php download problem.

    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");
    }
    else
    {
    //force download dialog
    header("Content-type: application/octet-stream\r\n");
    header("Content-disposition: attachment;
    filename=\"$fil e\"\r\n\r\n") ;
    header("Content-transfer-encoding: binary\r\n");
    header("Content-length: " . filesize($path) . "\r\n");
    }
    $fp=fopen($path , 'rb');
    fpassthru($fp);
    fclose($fp);

    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?

    Thanks.

    Kevin

  • Andy Hassall

    #2
    Re: php download problem.

    On 30 Aug 2005 11:56:11 -0700, "kevinm3574 " <kevintm@amerit ech.net> wrote:
    [color=blue]
    > header("Content-length: " . filesize($path) . "\r\n");
    > }
    > $fp=fopen($path , 'rb');
    > fpassthru($fp);
    > fclose($fp);
    >
    >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?[/color]

    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 :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    • kevinm3574

      #3
      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

      Kevin

      Comment

      Working...