Jump to content

output entire webpage to a file


penguine

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...