Problem with forced downloads via HTTP headers..

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Problem with forced downloads via HTTP headers..

    Hello,

    Can anyone verify / solve the problem I am having with downloading an
    image..

    The following test works fine in every browser I've tried except in mozilla
    for windows. Mozilla appends .php to the file name when prompted to save or
    open. In IE, I can save it to disk or open it, and the associated program
    opens the file. In Mozilla, it can't open the file because it displays the
    file like ... somefile.jpg.php

    Any ideas why?

    <?php
    $fpath = "../tmp/";
    $fname = "somefile.jpg";

    header( "Pragma: no-cache\n" );
    header( "Content-type: image/jpg\n" );
    header( "Content-Disposition: attachment; filename=\"$fname\"\n" );
    header( "Content-transfer-encoding: binary\n" );
    header( "Content-length: " . filesize($fpath . $fname) . "\n" );

    $fd = fopen($fpath . $fname, 'rb');

    while( !feof($fd) )
    {
    echo fread($fd, 4096);
    flush();
    }
    fclose( $fd );
    ?>


    Magnetotron Guest

  2. Similar Questions and Discussions

    1. Http headers...
      Hallo, Can't get reed fo http response headers Thow I used response.ClearHeaders wich MSDN say's it should clear all http headers I'm on VS 2005...
    2. http request headers
      I have a proxy which might delete/insert http request headers. I need a way to list the http request headers. How can i do it with perl. TIA,
    3. HTTP Headers
      On 2 Jul 2003 17:51:17 -0700, Jeff Mott <mjeff1@twcny.rr.com> wrote: First of all, Perl does not send HTTP requests. I will assume that you mean...
    4. #24961 [NEW]: website down for RC2 (http://downloads.php.net/ilia/php-4.3.3RC2.tar.bz2)
      From: no at email dot com Operating system: freebsd/mac etc PHP version: 4.3.3RC2 PHP Bug Type: *General Issues Bug...
    5. Getting all http headers
      Hi, I'm just starting out on ASP.NET, although I'm not new to programming. I'm in a crunch and have been all over the documentation and MSDN and...
  3. #2

    Default Re: [PHP] Problem with forced downloads via HTTP headers..

    * Thus wrote Magnetotron (magnetotron@hotmail.com):
    > Can anyone verify / solve the problem I am having with downloading an
    > image..
    >
    > <?php
    > $fpath = "../tmp/";
    > $fname = "somefile.jpg";
    >
    > header( "Pragma: no-cache\n" );
    > header( "Content-type: image/jpg\n" );
    Should be image/jpeg.
    > header( "Content-Disposition: attachment; filename=\"$fname\"\n" );
    Don't know if that is the problem but its worth a shot right now,
    mozilla usually is more trusting with reading headers than IE.

    Curt
    --
    "I used to think I was indecisive, but now I'm not so sure."
    Curt Zirzow Guest

  4. #3

    Default Re: [PHP] Problem with forced downloads via HTTP headers..

    Ok, I changed it to image/jpeg, and now the filename is....
    somefile.jpg.jpeg

    No matter what I do, Mozilla for windows wants to append another extension
    on the filename based on the mime type. Mozilla under linux works fine...

    "Curt Zirzow" <curt@zirzow.dyndns.org> wrote in message
    news:20030812010721.GR379@bagend.shire...
    > * Thus wrote Magnetotron (magnetotron@hotmail.com):
    > > Can anyone verify / solve the problem I am having with downloading an
    > > image..
    > >
    > > <?php
    > > $fpath = "../tmp/";
    > > $fname = "somefile.jpg";
    > >
    > > header( "Pragma: no-cache\n" );
    > > header( "Content-type: image/jpg\n" );
    >
    > Should be image/jpeg.
    >
    > > header( "Content-Disposition: attachment; filename=\"$fname\"\n" );
    >
    > Don't know if that is the problem but its worth a shot right now,
    > mozilla usually is more trusting with reading headers than IE.
    >
    > Curt
    > --
    > "I used to think I was indecisive, but now I'm not so sure."

    Magnetotron Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139