NYCPHP Meetup

NYPHP.org

[nycphp-talk] Anyway to force a download of GIF file?

FB` fb at intldef.org
Thu Jul 17 16:46:26 EDT 2003


> However IE on Mac seems to totally ignore the Content-disposition header
and will prompt to save as a .php file

as a solution to a similar problem, we used a combination of a Files
directive and $PATH_INFO -

the php script would be, for ex site.com/download (no extension) with a
Files directive like this in .htaccess:

<Files download>
        ForceType application/x-httpd-php
</Files>

Then, you pass it the desired image filename like this:

site.com/download/gifname.gif

the string gifname.gif would end up in var $PATH_INFO in the script named
download

then, you can fetch the file, etc etc, and push out the headers you want, as
described previously, by others.

you -could- do this with a script named something.gif, with the same Files
directive, but you'd lose the ability to set the proper name for the file.

hth

FB`

----- Original Message ----- 
From: "Jerry Kapron" <nyphp at NewAgeWeb.com>
To: "NYPHP Talk" <talk at lists.nyphp.org>
Sent: Thursday, July 17, 2003 3:41 PM
Subject: Re: [nycphp-talk] Anyway to force a download of GIF file?


> Mike,
> Change
>     header("Content-type: 'application/octet-stream");
> to
>     header('Content-type: application/force-download');
> It should fix the Mac problem.  However IE on Mac seems to totally ignore
the Content-disposition header and will prompt to save as a .php file.
>
> Jerry
>
> -----Original Message-----
> From: DeWitt, Michael <mjdewitt at alexcommgrp.com>
> To: 'NYPHP Talk' <talk at lists.nyphp.org>
> Date: Thursday, July 17, 2003 2:23 PM
> Subject: RE: [nycphp-talk] Anyway to force a download of GIF file?
>
>
> >Chris/Jerry,
> >
> >Thank you both for your suggestions.  Using headers is definitely the way
to
> >go.  After some playing around and reading up on compatibility issues,
here
> >is what I am working with so far:
> >
> ><?php
> >
> >header("Pragma: public");
> >header('Cache-Control: public');
> >header("Content-type: 'application/octet-stream");
> >header("Content-Length: ".filesize($FILE_PATH.$file));
> >header("Content-Disposition: attachment; filename=$file");
> >//echo "\\n";
> >readfile($FILE_PATH.$file);
> >
> >?>
> >
> >The Pragma and cache-control seem to be needed by IE6 in order to work.
the
> >content type "image/gif" gave me some issues where the file was
downloaded
> >but corrupted.  This stuff is completely ignored (broken) by IE on a
> >Macintosh, It will always just display the file.
> >
> >Thanks a lot for your help.
> >
> >Mike
> >
> >> -----Original Message-----
> >> From: Fee, Patrick J [SMTP:patrick.fee at baesystems.com]
> >> Sent: Thursday, July 17, 2003 12:11 PM
> >> To: 'shiflett at php.net'; 'NYPHP Talk'
> >> Subject: RE: [nycphp-talk] Anyway to force a download of GIF file?
> >>
> >> Chris,
> >>
> >> This is slightly off-topic, but do you have any idea how to do that in
> >> Cold
> >> Fusion?
> >>
> >> Patrick J. Fee
> >> Web & Database Group Manager
> >> BAE SYSTEMS
> >> 600 Maryland Ave. SW  Suite 600
> >> Washington D.C. 20024
> >> Patrick.Fee at BAESYSTEMS.com
> >> Tel: (202) 548-3759
> >> Fax: (202) 608-5970
> >>
> >>
> >>
> >> -----Original Message-----
> >> From: Chris Shiflett [mailto:shiflett at php.net]
> >> Sent: Thursday, July 17, 2003 10:55 AM
> >> To: NYPHP Talk
> >> Subject: Re: [nycphp-talk] Anyway to force a download of GIF file?
> >>
> >>
> >> --- "DeWitt, Michael" <mjdewitt at alexcommgrp.com> wrote:
> >> > I have been looking around for a way to get browsers to download
> >> > rather than display a GIF file.
> >>
> >> Have you looked into the Content-Disposition header? With it you can
> >> specify
> >> a
> >> filename (convenient when the name of your PHP script isn't the name
you
> >> want
> >> the browser to use), and you can indicate inline or attachment. You
would
> >> want
> >> attachment.
> >>
> >> Double-check my syntax, but I think it would go something like this:
> >>
> >> header('Content-Disposition: attachment; filename=blah.gif');
> >>
> >> Hope that helps.
> >>
> >> Chris
> >>
> >> =====
> >> Become a better Web developer with the HTTP Developer's Handbook
> >> http://httphandbook.org/
> >> _______________________________________________
> >> talk mailing list
> >> talk at lists.nyphp.org
> >> http://lists.nyphp.org/mailman/listinfo/talk
> >> _______________________________________________
> >> talk mailing list
> >> talk at lists.nyphp.org
> >> http://lists.nyphp.org/mailman/listinfo/talk
> >_______________________________________________
> >talk mailing list
> >talk at lists.nyphp.org
> >http://lists.nyphp.org/mailman/listinfo/talk
> >
>


----------------------------------------------------------------------------
----


> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
>




More information about the talk mailing list