Jump to content

Archived

This topic is now archived and is closed to further replies.

lonewolf277

Using HTML headers in PHP

Recommended Posts

Hey everybody, not sure if this should go into the HTML help section, or maybe even in the database section under MySQL, but I'm using PHP code, so I thought I'd try here first. Sorry if it's a mis-post! ;)

I'm having a problem with using headers to allow a user to save a file which is stored as a blob in a database [MySQL]. Specifically, when the user clicks on a link to the file, I have a 'getFile.php' file which gets the data from the database, and sends it to the user, using headers [code below]. The problem is, if the user selects "Open", then the file isn't displayed, something about how the "path or file name is invalid". Even more interestingly, the problem only seems to exist in IE, and the PHP works fine in Firefox!

Here is the code snippet [runs when the user clicks on the link for a file]:

[code]
// $content_type is something like 'application/vnd.ms-powerpoint'...
// $file_name is usually 'presentation.ppt'...
// $length is just the file length, in bytes...
// $file is the file data, taken from the blob in the DB...
header ("Content-type: " . $content_type);
header ("Content-Disposition: attachment; filename=" . $file_name);
header ("Content-length: " . $length);
echo $file;
exit();
[/code]

Has anyone experienced anything like this before? I've tried searching for hours with no luck! Thanks in advance for any help anyone can give me!

A side note: someone just suggested to me that perhaps IE doesn't completely load the file before it tries to open it in the associated program. Not sure if that helps... ???

Share this post


Link to post
Share on other sites
Well, seemed to figure it out myself, so here's my solution to anyone who might be having the same sort of problem:

[code]
// $content_type is something like 'application/vnd.ms-powerpoint'...
// $file_name is usually 'presentation.ppt'...
// $length is just the file length, in bytes...
// $file is the file data, taken from the blob in the DB...
header ("Content-type: " . $content_type);
// this line was changed...
//header ("Content-Disposition: attachment; filename=" . $file_name);
// to this...
header ("content-Disposition: inline; filename=" . $file_name);
header ("Content-length: " . $length);
echo $file;
exit();
[/code]

Hope this helps! 8)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.