imageJPEG() - saving result from browser with filename while using sessions

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

    imageJPEG() - saving result from browser with filename while using sessions

    Hi,

    I've created a PHP file called filename.jpg. It outputs a JPG. I've set up
    a .htaccess file to force the filetype to PHP. The file is displayed in a
    page on a browser. I cannot get the damn thing to save as my suggested
    filename or even as anything but a BMP in IE6. I've tried a bunch of
    different combinations of the content-type and content-disposition (inline,
    attachment, filename, name) headers. Nothing has worked.

    I've tried all combinations of the following header() string (regex for
    brevity-I didn't actually use the regex characters):

    Content-(T|t)ype: image/jpeg(; (file)?name="?x x.jpg"?)?

    with and without:
    Content-(D|d)isposition : (inline|attachm ent)(; (file)?name="?x x.jpg"?)?

    followed by:
    ImageJPEG($im,' ',60);

    After many hours pounding my head against the wall and RingTFingM, I
    realized 2 things as I was writing this post.

    The first is that I'm using session_start() . Take it out and I have no
    trouble.

    The second is that I've encountered this problem before, spent hours on it,
    and finally gave up and passed all parameters to the script by $_GET.

    I'd rather not do that again. The image is being used as a server-side
    image map. Does anyone know how I can use session_start AND the
    Content-disposition header? I've tried placing the header before
    session_start, to no avail.

    Thanks a bunch,
    Shawn
    --
    Shawn Wilson
    shawn@glassgian t.com



  • Pedro Graca

    #2
    Re: imageJPEG() - saving result from browser with filename while using sessions

    Shawn Wilson wrote:[color=blue]
    > I've created a PHP file called filename.jpg. It outputs a JPG. I've set up
    > a .htaccess file to force the filetype to PHP. The file is displayed in a
    > page on a browser. I cannot get the damn thing to save as my suggested
    > filename or even as anything but a BMP in IE6. I've tried a bunch of
    > different combinations of the content-type and content-disposition (inline,
    > attachment, filename, name) headers. Nothing has worked.[/color]
    [color=blue]
    > The first is that I'm using session_start() . Take it out and I have no
    > trouble.
    >
    > The second is that I've encountered this problem before, spent hours on it,
    > and finally gave up and passed all parameters to the script by $_GET.[/color]

    You have a browser problem :)
    What you describe does not happen for Mozilla :))

    Based on the fact that removing session_start() made me think that could
    be something with the headers; so I tried removing headers from the
    script. The end result was:

    I have another php script that sets $_SESSION['txt'] without ini_set()s
    and outputs a <img src="xx.jpg.php "/> (no .htaccess)

    <?php // xx.jpg.php
    ini_set('sessio n.use_cookies', '0');
    ini_set('sessio n.cache_limiter ', '');
    ini_set('sessio n.cache_expires ', '');
    session_start() ;

    $im = imagecreate(200 , 60);
    $bg = imagecoloralloc ate($im, 255, 255, 255);
    $black = imagecoloralloc ate($im, 0, 0, 0);
    imagestring($im , 5, 10, 20, $_SESSION['txt'], $black);

    header('Content-Type: image/jpeg');
    header('Content-Disposition: inline; filename="xx.jp g"');
    imagejpeg($im, '', 60);
    imagedestroy($i m);
    ?>
    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--

    Comment

    • Shawn Wilson

      #3
      Re: imageJPEG() - saving result from browser with filename while using sessions

      Pedro Graca <hexkid@hotpop. com> wrote in message news:<c1ki6g$1j ceh9$1@ID-203069.news.uni-berlin.de>...[color=blue]
      > Shawn Wilson wrote:[color=green]
      > > I've created a PHP file called filename.jpg. It outputs a JPG. I've set up
      > > a .htaccess file to force the filetype to PHP. The file is displayed in a
      > > page on a browser. I cannot get the damn thing to save as my suggested
      > > filename or even as anything but a BMP in IE6. I've tried a bunch of
      > > different combinations of the content-type and content-disposition (inline,
      > > attachment, filename, name) headers. Nothing has worked.[/color]
      >[color=green]
      > > The first is that I'm using session_start() . Take it out and I have no
      > > trouble.
      > >
      > > The second is that I've encountered this problem before, spent hours on it,
      > > and finally gave up and passed all parameters to the script by $_GET.[/color]
      >
      > You have a browser problem :)
      > What you describe does not happen for Mozilla :))
      >
      > Based on the fact that removing session_start() made me think that could
      > be something with the headers; so I tried removing headers from the
      > script. The end result was:
      >
      > I have another php script that sets $_SESSION['txt'] without ini_set()s
      > and outputs a <img src="xx.jpg.php "/> (no .htaccess)
      >
      > <?php // xx.jpg.php
      > ini_set('sessio n.use_cookies', '0');
      > ini_set('sessio n.cache_limiter ', '');
      > ini_set('sessio n.cache_expires ', '');
      > session_start() ;
      >
      > $im = imagecreate(200 , 60);
      > $bg = imagecoloralloc ate($im, 255, 255, 255);
      > $black = imagecoloralloc ate($im, 0, 0, 0);
      > imagestring($im , 5, 10, 20, $_SESSION['txt'], $black);
      >
      > header('Content-Type: image/jpeg');
      > header('Content-Disposition: inline; filename="xx.jp g"');
      > imagejpeg($im, '', 60);
      > imagedestroy($i m);
      > ?>[/color]

      Just a follow-up. This worked great. I didn't think it would because
      I expected it not to read the cookie info after session.use_coo kies
      was turned off. But apparently it reads the sessionid from the
      cookie, uses it to load the session variables, then turns cookies off
      before it sends the cookie back to the browser. All of which makes
      perfect sense now that I type it out and really think it through.

      All browsers I test on save as jpg now, though NS6 disregards
      suggested filename. But the important thing was to allow them to save
      as jpg. Filename was just a bonus.

      End result is:

      if you're interested.

      Thanks Pedro,
      Shawn

      Comment

      • Pedro Graca

        #4
        Re: imageJPEG() - saving result from browser with filename while using sessions

        Shawn Wilson wrote:[color=blue]
        > Just a follow-up. This worked great.[/color]

        You had me wondering here :)
        Thanks for the feedback
        --
        --= my mail box only accepts =--
        --= Content-Type: text/plain =--
        --= Size below 10001 bytes =--

        Comment

        Working...