Hello all,
I am currently looking for a solution to my PDF creation issue. First, I can successfully create a PDF using htmldoc (Linux-based) from many different clients' MySQL data. My first question would be - Is there a way to generate the PDF's filename from a DB so that each PDF is uniquely named and move it to the appropriate "reports" folder that I desire?
Additionally, I would like to have a PHP or possibly even shell script which would run with Cron to take the newly created PDF, archive it according to the date the report was run, and email it to the client's designated email address. The email address and client info would be pulled from a MySQL db. One of the key requirements is that the script iterate through the DB so as to create/email PDF for each respective client. Obviously my goal is total automation.
I realize this is a lot to request but I have been working diligently for some time and only been able to come up with some minor solutions. Thanks for all of your participation and answers. They will be appreciated.
Brandon (phishee)
Convert dynamic PHP report to PDF and then email results
Moderator: General Moderators
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
Everything you say is very possible. First check the htmldoc help files to see how you name the files how you like, and then use the name that you get from a database query. Then as you say use cron to run another script to email and store everything you want, it would be a fairly simple task of looping through the results you get from the database.
You have said exactly what you want to do, so get some flow charts drawn up to show you how everything will work and then code it. Then ask any more questions if you get stuck.
You have said exactly what you want to do, so get some flow charts drawn up to show you how everything will work and then code it. Then ask any more questions if you get stuck.
Imho the best idea is to generate filename as timestamp. Something like "month-day-year-hours-minutes-seconds.pdf" or something. This must give you and unique filename.Is there a way to generate the PDF's filename from a DB so that each PDF is uniquely named and move it to the appropriate "reports" folder that I desire?
First you run shell command something likeI would like to have a PHP or possibly even shell script which would run with Cron to take the newly created PDF, archive it according to the date the report was run, and email it to the client's designated email address. The email address and client info would be pulled from a MySQL db. One of the key requirements is that the script iterate through the DB so as to create/email PDF for each respective client. Obviously my goal is total automation.
shell_exec() (http://www.php.net/manual/en/function.shell-exec.php) or system() (http://www.php.net/manual/en/function.system.php), exec() (http://www.php.net/manual/en/function.exec.php). Ie
Code: Select all
shell_exec("/usr/.../htmldoc")then gzip the result file (see shell_exec);
Then run query selecting emails from database and then walking thru resulting array mail it to client.
Code: Select all
$result = mysql_query("select EMAIL_FIELD from TABLE");
while ($email = mysql_fetch_array($result))
{
//build MIME message and send mail to the address $emailї'EMAIL_FIELD']
//your hosting provider may have already PHP MIME class set up
//or you can make it with your own (find in google "PHP MIME mail")
}Hope this will help you. If you have any question - post it here. Good luck