Jump to content

Using HTML headers in PHP


lonewolf277

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... ???
Link to comment
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)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.