|
|
|
|
![]() ![]() |
Nov 22 2006, 11:46 AM
Post
#1
|
|
|
Super Member Group: Members Posts: 555 Joined: 29-September 06 Member No.: 16,228 |
I have little knowlegde of PHP, and none/never done a cron job.
How would I save two images that change every ten minutes on another website? Maybe add a timestamp and put them in a folder. |
|
|
|
Nov 22 2006, 08:23 PM
Post
#2
|
|
|
Super Member Group: [HOSTED] Posts: 805 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 myCENTs:46.87 |
Well i dont know if it is possible to do it but what i know is that it is a bit difficult to use cron jobs with php, may be i'm wrong.
Best regards, |
|
|
|
Nov 23 2006, 05:16 AM
Post
#3
|
|
|
Member [ Level 2 ] Group: Members Posts: 53 Joined: 11-November 06 Member No.: 17,170 |
why to use corn jobs to save images?
i can think of anything that this thing will halp in :\ NoMore |
|
|
|
Nov 23 2006, 05:20 AM
Post
#4
|
|
|
Super Member Group: [HOSTED] Posts: 500 Joined: 5-November 06 Member No.: 17,016 myCENTs:NEGATIVE[-20.12] |
I've use cron jobs to access a php script that does something, everyday. It's for my hotel management system, where the system will post the room charges automatically everyday. I didn't call the cgi version, instead i use wget to call the page locally
CODE wget -q http://localhost/autopost.php -O - >> /home/myfolder/logs that way, the page will run exactly the same as if it runs from a browser, and the text output is appended to the logs in myfolder. toby, if the image you're trying to save has static url, then it would be easier. But i'm not sure of the exact way of doing it. If the url is static, maybe you can use fopen() to open the file stream of the image, then save it to another handle to a local file(open with fopen() with mode = x) with fwrite(). Seems complicated. Another way is to use wget to download the file programatically to the temp folder, then use rename() to move that file to your desire destination and at the same time rename it to your choice If the url is not static, things get a bit more complicated, you'll have to parse the page that holds the image manually, to get the url of the image, then continue with the above method. the parse might be able to do with DOM, but i'm not sure and never did. The above is just a suggestion of concept, it's not proven to work. But might give you some idea of where to start. Try read the manual of those mentioned php function, the comment section might provide more hints Good luck This post has been edited by faulty.lee: Nov 23 2006, 05:22 AM |
|
|
|
Nov 23 2006, 11:27 AM
Post
#5
|
|
|
Super Member Group: Members Posts: 555 Joined: 29-September 06 Member No.: 16,228 |
http://www.bbc.co.uk/radio1/webcam/images/live/webcam2.jpg And http://www.bbc.co.uk/radio1/webcam/images/live/webcam.jpg
So how would the php script go? What access does wget need? |
|
|
|
Nov 23 2006, 02:37 PM
Post
#6
|
|
|
Super Member Group: [HOSTED] Posts: 500 Joined: 5-November 06 Member No.: 17,016 myCENTs:NEGATIVE[-20.12] |
http://www.bbc.co.uk/radio1/webcam/images/live/webcam2.jpg And http://www.bbc.co.uk/radio1/webcam/images/live/webcam.jpg So how would the php script go? What access does wget need? This is a crude method, but i just tested, and works on my side. Save this as /home/myhome/test.php CODE $temp_filename = "webcam-" . date('Y-m-d-G.i') . ".jpg"; system('wget -q http://www.bbc.co.uk/radio1/webcam/images/live/webcam.jpg -O /home/myhome/' . $temp_filename); echo "Done fetching " . $temp_filename . "\n"; the code first generate a temp filename from the current server time then call wget to download the image and save as the filename generated edit your crontab as CODE */10 * * * * php < /home/myhome/test.php EDIT: you can refer to crontab here http://en.wikipedia.org/wiki/Cron you can use php or php-cgi the output will be CODE Content-type: text/html X-Powered-By: PHP/5.0.4 Done fetching webcam-2006-11-23-22.32.jpg If you want to log the output of the php, just add a redirection like this CODE * * * * */10 php < /home/myhome/test.php > /home/myhome/logs That's all. One thing though, i don't know how to remove the http header from the php output. Anyway, the rest is up to you to refine. Good luck This post has been edited by faulty.lee: Nov 23 2006, 02:40 PM |
|
|
|
Nov 23 2006, 05:32 PM
Post
#7
|
|
|
Super Member Group: Members Posts: 595 Joined: 4-September 04 Member No.: 228 |
If you're going to use system calls it's kind of pointless to use PHP then. I mean why bother with PHP when a simple shell script would do the job. Problems tend to rise when you're not on your own server as system calls from PHP usually are blocked (and for a good reason).
Loading an image from an URL is actually not that difficult. If you have fopen wrapper enabled you can just pass the URL as parameter to imagecreatefromjpeg() (you can replace jpeg with gif or png too) function . Then just do whatever you want to the image, resize it, save it, push it to database, etc. If the wrapper is not enabled you then need to open a filehandle (just fopen(http://image.com/image.png) ) and read the binary to a variable using fread() and then proceed with imagecreatefrom*(). EDIT: Please post if you need more detailed examples. This post has been edited by Hercco: Nov 23 2006, 05:33 PM |
|
|
|
Nov 24 2006, 04:05 AM
Post
#8
|
|
|
Super Member Group: [HOSTED] Posts: 500 Joined: 5-November 06 Member No.: 17,016 myCENTs:NEGATIVE[-20.12] |
Hi Hercco,
I do admit that i wasn't very good with linux and shell script. Just trying to give a working example. I've tested that on a linux server where i've quite a lot of rights given. Anyway, you idea seems cleaner from php point of view. |
|
|
|
Nov 24 2006, 04:22 AM
Post
#9
|
|
|
Super Member Group: [HOSTED] Posts: 805 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 myCENTs:46.87 |
Yes, what Hercco said is correct, because in most cases hosting providers disable the system function for security reasons, so i think that the solutions he proposes are better to use.
Best regards, |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 4th December 2008 - 03:16 AM |