Re: PHP quickie - readfile equiv

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

 



Hi folks.

I'm trying to write a script to read details from a SQL database, insert data into a file and download it to the user's browser. If I use the readfile function it works, but if I use get_file_contents and echo the file doesn't get downloaded properly. In both cases, Mozilla opens oowriter, but with readfile the document appears correctly, while with get_file_contents/echo it show the rich text code.

Anyone any ideas?

Gary

<? // vim: ft=php nowrap ai et include_once("gsql1.inc");
include_once("gsecurity.inc");

list($dummy,$o_id,$fname)=explode("/",$_SERVER['PATH_INFO']);
$dets=array_shift(loadhash3("select o_id as key, * from order_details where o_id=$o_id"));
if (!$dets['o_id']) {
  echo "Order Details Missing";
  exit;
}
$contents=file_get_contents("/home/httpd/files/$fname");
if ($contents == false) {
  echo "Document Missing";
  exit;
}
header("Content-Type: text/rtf");
header('Content-Disposition: attachment; filename="delivery_note.rtf"');
#readfile("/home/httpd/files/$fname");
echo $contents;


Readfile() is the correct way to do this. See manual (header()).

Lauri



[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux