Web Hosting Talk







View Full Version : image Fetching script needed


mjeffscds
03-11-2006, 05:15 PM
Hi can some one help me out i am looking for a php script that will fecth the webcam image locate on http://www.harrisnorwood.org.uk/webcam_image.php every hour and save it to my server

jabab
03-11-2006, 05:38 PM
Untested...
$file_source="url here";
$file_target="c:/" . time();
$rh = fopen($file_source, 'rb');
$wh = fopen($file_target, 'wb');
if ($rh===false || $wh===false) {
die("File read/write error");
}

while (!feof($rh)) {
fwrite($wh, fread($rh, 1024));
}
fclose($rh);
fclose($wh);

mjeffscds
03-11-2006, 06:09 PM
hi i thanks for you help i have sent you a pm

with the code change it should look something like

$file_source="http://www.harrisnorwood.org.uk/webcam_image.php";
$file_target="http://www.mjeffs.info/images" time();
$rh = fopen($file_source, 'rb');
$wh = fopen($file_target, 'wb');
if ($rh===false || $wh===false) {
die("File read/write error");
}

while (!feof($rh)) {
fwrite($wh, fread($rh, 1024));
}
fclose($rh);
fclose($wh);

but how do i set the time so it checks http://www.harrisnorwood.org.uk/webcam_image.php at 2 mins pass the hour each hour and then Fetchs the image and saves it on my server also how do i set it up so that the picture it not just saved as webcam_image and overwritten each hour

jabab
03-12-2006, 08:46 AM
hi i thanks for you help i have sent you a pm

with the code change it should look something like

$file_source="http://www.harrisnorwood.org.uk/webcam_image.php";
$file_target="http://www.mjeffs.info/images" time();
$rh = fopen($file_source, 'rb');
$wh = fopen($file_target, 'wb');
if ($rh===false || $wh===false) {
die("File read/write error");
}

while (!feof($rh)) {
fwrite($wh, fread($rh, 1024));
}
fclose($rh);
fclose($wh);

but how do i set the time so it checks http://www.harrisnorwood.org.uk/webcam_image.php at 2 mins pass the hour each hour and then Fetchs the image and saves it on my server also how do i set it up so that the picture it not just saved as webcam_image and overwritten each hour
Change
$file_target="http://www.mjeffs.info/images" time();
to
$file_target=getcwd() . "/images/" . time();
Then run upload the script to your host, if the page loads and is blank, that's good. Look into cron jobs to run it every hour.

mjeffscds
03-12-2006, 11:11 AM
yeah thanks that works and i think i set the cron job is set up correctly but their is one other thing when i load the image forlder by connecting to the server by ftp the files are not jpg however when i go to www.mjeffs.info/images and click on them their are is their a quick fix for this.

jabab
03-12-2006, 03:55 PM
Change
$file_target=getcwd() . "/images/" . time();
to
$file_target=getcwd() . "/images/" . time() . ".jpg";
For obvious reasons...
Also check out www[dot]webcron[dot]/index.php?&lang=en

Burhan
03-13-2006, 02:18 AM
Just add:

wget -Nqk -O images/webcam.jpg http://www.harrisnorwood.org.uk/webcam_image.php

to your cron. No need to do any PHP.

mjeffscds
03-13-2006, 03:30 PM
i just get images/webcam.jpg: No such file or directory in the email sent when the server trys to do the cron job