Re: Content Header

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 






On Wed, July 20, 2005 7:32 am, Christopher J. Umina said:
> Hello!
>
> I currently have a script which streams data out of a MySQL database,
> and prints the content headers correctly, however, when I use the
> following line:
>
> header("Content-Disposition: attachment; filename=\"". $filename ."\"");
>
> it prompts the user to download the file each time they go to the site.
>   The problem is, I want the filename to be in the header, incase
> somebody right clicks and saves the file, but I don't want the user to
> be prompted to download the file when they're just trying to look at
> it.  Does anybody know a way I can achieve this result?

Sure!

Just cram $filename onto the end of your URL in the first place:

Instead of:
http://example.com/yourscript.php

Use this:
http://example.com/yourscript.php/<?php echo $filename?>

The browsers are SO STUPID they'll see that as the "filename" -- most of
them.

The "trick" to get the ones that are really really stupid and still insist
on using "yourscript.php" is to get rid of the ".php" and just call it
"yourscript"

Of course, then it's not a PHP script, so you have to tell Apache that it
*IS* a PHP script, even if it has no ".php" on the end.

Put this in an .htaccess file next to "yourscript":

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


So *NOW* your URL looks like:
http://example.com/yourscript/<?php echo $filename?>

There ain't no way the browser will be able to screw up, because it has NO
IDEA you have PHP generating the content.

If you give the browser-makers any opportunity to screw up, one of them
will in some version or other.  So don't let them have a chance to screw
up.  Make a URL they can't "know" is PHP.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux