Web Hosting Talk







View Full Version : php scripts needed


Joshua44
07-11-2003, 07:24 AM
I need a php script that checks to see if an image exists on a remote server.
Also, if anyone could help me with seeing how many days/yrs/hours/etc has passed between 2 time stamps...

Thanks.

Slidey
07-11-2003, 07:28 AM
straight off the php site (sigh)

klaas at kosmokrator dot com
02-Jun-2003 09:19

To get the number of days between two dates, you can use this:


function DaysBetween( $date1, $date2 ) {
return ( date( "Y", $date1 ) * 366 + date( "z", $date1 ) ) -
( date( "Y", $date2 ) * 366 + date( "z", $date2 ) );
}


http://www.php.net/manual/en/function.date.php

theres other ones there too

Joshua44
07-11-2003, 02:07 PM
image checking please? That was the main point of my post. Don't get mad about the date thing, I have looked at php.net before, and I thought that as long as I was posting anyway I might as well ask that.

kevint8
07-11-2003, 04:35 PM
The easiest way I can think of is this:


$remote_file = "http://www.domain.com/images/filename.jpg";

if (@fopen($remote_file,'r')) {
echo "File exists!";
} else {
echo "File does not exist!";
}


The only downside to this is it will hang if the remote server is down. The workaround for that would to ping the remote server before trying the above method. If the ping comes back as timed out, then assume that the file doesn't exist.