How to save PDF automatically via cron job or other way?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
micastle
Forum Newbie
Posts: 3
Joined: Fri Feb 04, 2011 12:01 pm

How to save PDF automatically via cron job or other way?

Post by micastle »

I usually go to a web site every day and open their daily different PDF and then click on the PDF diskette icon and save it locally to my computer hard disk.

What I need is a script to save it not to my local hard disk but to my server and automatically. Essentially: move a PDF whose daily address on a public server not mine I know to a folder on my server so a number of PDFs are stored daily and automatically there with no need for me to use my browser and download locally first using my browser. I know how to create a cron job for any script to run at fixed time intervals but can't figure out what script to assign to the cron for the unattended automatic downloads. Any ideas? Can this be done at all?

Thanks
litebearer
Forum Contributor
Posts: 194
Joined: Sat Mar 27, 2004 5:54 am

Re: How to save PDF automatically via cron job or other way?

Post by litebearer »

if you KNOW the url for the pdf file, you could use curl in a script that will grab it and save it. the cron could run the script at the appointed time.
micastle
Forum Newbie
Posts: 3
Joined: Fri Feb 04, 2011 12:01 pm

Re: How to save PDF automatically via cron job or other way?

Post by micastle »

I seached for cURL and it seems it has to be installed in the server of which I am not the administrator. Can this be done using file_get_contents instead?

Once I have the file in the 'contents' variable how can I save it as a PDF? Do I need to do something (header configurationm, etc) so the file_get_contents funtion retrieves the PDF in the correct format to save it as PDF? How do I save it as PDF?

Thanks
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: How to save PDF automatically via cron job or other way?

Post by John Cartwright »

Code: Select all

file_put_contents($file_name_to_save_as, file_get_contents('http://url_of_the.com/document.pdf'));
:)
micastle
Forum Newbie
Posts: 3
Joined: Fri Feb 04, 2011 12:01 pm

Re: How to save PDF automatically via cron job or other way?

Post by micastle »

John Cartwright wrote:

Code: Select all

file_put_contents($file_name_to_save_as, file_get_contents('http://url_of_the.com/document.pdf'));
:)
Thanks. Works fine!!
Post Reply