Jump to content


Photo

Using HTML headers in PHP


  • Please log in to reply
1 reply to this topic

#1 lonewolf277

lonewolf277
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 27 October 2006 - 09:18 AM

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... ???

#2 lonewolf277

lonewolf277
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 27 October 2006 - 10:52 AM

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

// $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();

Hope this helps! 8)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users