You are here: Re: [PHP] Content Header « PHP « IT news, forums, messages
Re: [PHP] Content Header

Posted by "Richard Lynch" on 07/22/05 09:11

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация