Fetch and save image
Moderator: General Moderators
Fetch and save image
Hi,
I'm at a very beginning stages of PHP. So I hope someone can help me with this problem. I'm trying to fetch an image from a Department of Transportation webcam and store it on my server for post processing.
How do I copy the image over?
Obviously copy("http://www.......something.jpg", "local.jpg") doesn't work.
Thank you!
Mounir
I'm at a very beginning stages of PHP. So I hope someone can help me with this problem. I'm trying to fetch an image from a Department of Transportation webcam and store it on my server for post processing.
How do I copy the image over?
Obviously copy("http://www.......something.jpg", "local.jpg") doesn't work.
Thank you!
Mounir
feyd | Please use
but it gets me the following messages:
[/quote]
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
So this is what I tried:Code: Select all
<?php
$old = "http://www.tripcheck.com/RoadCams/cams/I-5_Millplain_pid771.jpg";
$new = "i5mill.jpg";
$image = substr(file_get_contents($old),0,-1);
$handle = fopen($new, "w");
fwrite($handle, $image);
fclose($handle);
?>Code: Select all
Warning: fopen(i5mill.jpg): failed to open stream: Permission denied in /home/citycamv/public_html/tc/tc.php on line 8
Warning: fwrite(): supplied argument is not a valid stream resource in /home/citycamv/public_html/tc/tc.php on line 9
Warning: fclose(): supplied argument is not a valid stream resource in /home/citycamv/public_html/tc/tc.php on line 10feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]feyd | Please use
Any ideas?
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Slightly different problem.
So I wrote a little piece of code that copies from ODOT cams to my server. It works if I execute the code from a browser, but I want to set it up as a CRON job. When I do I get no error messages, but the images are not copied to where I expect to see them (actually I can't find them at all).Code: Select all
<?php
header("Cache-Control:no-cache");
$conn = mysql_connect("localhost", "mydatabase", "password")
or die("Nope...");
mysql_select_db("mydatabase") or die("<span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span>-o");
$sql = "select * from orhwy";
$rs = mysql_query($sql);
while ( $row = mysql_fetch_array($rs) ) {
$old = "http://www.tripcheck.com/RoadCams/cams/".$row["image"];
$new = $row["file"];
$image = substr(file_get_contents($old),0,-1);
$handle = fopen($new, "w");
fwrite($handle, $image);
fclose($handle);
}
echo ("Finished copying");
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
you may need to specify the exact directory you want the files to be saved to as the script is likely being run from a different directory than browsing to it would. As for errors, you may want to check the server logs, but it may not show up. You can look into telling PHP to write a log of errors to a certain file via a multitude of ways through the error_log ini directive.