Hello, I am having a problem and tired finding a solution on Google. Here is the scenario. I have a php shopping cart and the cart after final checkout, generates an invoice. The invoice layout and page has been created in php. for example. domain.com/invoice.php?cid=xxx&sid=xxx Now this page serves perfectly fine in my browsers like I want with all purchase details of the customer. This invoice.php page is actually an exact printable invoice with just a company logo and CSS and html table layout. No extra images or something. All I need, is that when the invoice.php is executed, it should have a php code which should save the same invoice output as .html file on the ftp folder. Thanks.
The simplest way would be to create a special url where you specify the same details as you are, but a security key as well, and then call the url using file_get_contents('http://www.yourdomain.com/file.php?sid=12345&cid=12345&passcode=blahblah"); then save the file using the file_put_contents function
One way to do it would be to use ob_start() before the page is output to turn on output buffering and $page = ob_get_contents(); //capture buffered output file_put_contents("filename",$page); //save it ob_end_flush(); //display it to end user PHP:
I agree with Gray_Fox's solution because at times contents are not simply received through url calls, but through post methods and curl outputs. However, if url is called simply using get parameter's JAY6390 has already suggested a good method. Try both the methods and use best suitable for you
well, I tried this too. but it does not execute php in the file contents. it shows its code as html. I some how sorted that issue. But now I am looking for another solution. When the invoice page loads, it generates a PDF and attaches and emails the PDf invoice to the customer. the problem is, PDF generation takes time, like 1 or 2 minutes, but the email sending code below it executes at the same time and as a result, it sends a PDf file with 0KB, because when the email function executed, the PDF was not completely generated. Is there a way to code php with some time frame? like after page load, email function should be execute after 5 minutes? thanks for the help
So you wanted to save the page with the PHP code still unexecuted in it? what exactly would be the point in that?
no, I do not want to save the php page anymore I have sorted that already. I need to know about the php code to be executed after a specific number of minutes or seconds. thanks
I see. You could just use the sleep() function before your mail() function and set it to say 3 minutes so that the script delays for 3 minutes before sending. Another solution would be to check the file size of the file in a do while loop until it's not 0KB. Other than that, the only other solution I can suggest is to have a db table log the time the pdf starts generating and then have a cron job run your mail script for every file that's been generated say 5 minutes ago or more that hasn't been sent