On Monday 05 June 2006 13:36, Lauri wrote: > > 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 Hi Lauri, Thanks for that, but I can't use readfile because I need to change the contents of the file between the get_file_contents and the echo. Gary -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000