penguine Posted June 7, 2007 Share Posted June 7, 2007 Hi How can we output an entire web page(voucher) to a file.If i have 100 vouchers and i want to output it to a single file .is it possible? Link to comment Share on other sites More sharing options...
vijay Posted June 7, 2007 Share Posted June 7, 2007 Hi.. that mean you want to store those all in to one html files..?-Vijay Link to comment Share on other sites More sharing options...
penguine Posted June 7, 2007 Author Share Posted June 7, 2007 I already have a php code which displays entire vouchers in a single html page.I want to store the generated vouchers in the server for future reference.is it possible? Link to comment Share on other sites More sharing options...
vijay Posted June 7, 2007 Share Posted June 7, 2007 Hi.. if you are not changing after generating it..then you need not to store voucher @ server side.. only by some event you have all the records what ever on voucher... and still you want to save the with the help of CURL... as following------------------------------------------------------------------------<?php$ch = curl_init("http://www.example.com/"); // write here your voucher generating url...$fp = fopen("example_homepage.txt", "w");curl_setopt($ch, CURLOPT_FILE, $fp);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);$output=curl_exec($ch);curl_close($ch);fclose($fp);if ($handle = fopen("myvoucher.html", 'a')) // it saves on server in the current directory from where file is executing{ fwrite($handle, $output); }fclose($handle);?> Regards,Vijay Link to comment Share on other sites More sharing options...
Mr_CHISOL Posted June 7, 2007 Share Posted June 7, 2007 You can use the output control functions to catch the output..Something like this: <?phpob_start()/** The page etc... **/// Get the outputted text..$output = ob_get_clean();// Save the output to a file...if (!file_put_contents( 'file.html', $output )) { echo "Couldn't save to file 'file.html'!<br />\n";}// Output the (buffered) outputecho $output;?> Link to comment Share on other sites More sharing options...
vijay Posted June 7, 2007 Share Posted June 7, 2007 Hi..From th following code also you cam do this.. my prev. code have some probs..:)so sorry for that... ---------------------------------------------------$ch = curl_init("http://localhost:9000/test/casestudy.html");$fp = fopen("mycase.html", "w");curl_setopt($ch, CURLOPT_FILE, $fp);curl_setopt($ch, CURLOPT_HEADER, 0);//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);$output=curl_exec($ch);curl_close($ch);fclose($fp);Regards,Vijay Link to comment Share on other sites More sharing options...
penguine Posted June 8, 2007 Author Share Posted June 8, 2007 Great that's worked. I slightly changed the code file_put_content to $filename="voucher.html"; if (!$handle = fopen($filename, 'w')) { echo "Cannot open file ($filename)"; exit; }// Save the output to a file...if(!fwrite($handle ,$output)) { echo "Couldn't save to file 'voucher.html'!<br />\n";} in order to work under PHP4.Many thanks for Mr_CHISOL and vijay for helping me. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.