im programming a photo gallery that will grab thumbnails and photos that are hosted in photobucket. photobucket gives you the direct link to your photo files.
now, i programmed the little script using file_exists, the path to the image is fine, but i guess file_exists does not work on files in other web servers.
is there a function that will allow me to see if a file exists in another web server?
sekasi
June 12, 2008, 3:47pm
2
fopen will return false if you cant open it (allow_URL_FOPEN) gotta be true in the ini file tho…
it tells me that URL file-access is disabled in the server configuration. i guess i have to make changes to the php.ini file.
i can create the paths to the img tag, is there a way to find out if the link is broken so when its not it will not display it?
I just read that setting allow_url_open is a huge security risk.
I just want to check if the image in the photobucket link exists. any other way?
i had to do this once, you can do it with curl. i set this up w/ a demo image for you
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://l.yimg.com/g/images/home_photo_jam343.jpg");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
$data = curl_exec($ch);
curl_close($ch);
preg_match_all("/HTTP\/1\.[1|0]\s(\d{3})/",$data,$matches);
$code = end($matches[1]);
if(!$data)
{
echo "file could not be found";
}
else
{
if($code == 200)
{
echo "file found";
}
elseif($code == 404)
{
echo "file not found";
}
}
?>
this isn’t my code i found it a long time ago but don’t remember where, so I can’t take any credit for it
[ot]
fyi fopen on most servers will be turned off cause of the security risk
[/ot]
Thanks! I just copy and pasted the code and did some minor changes. It works great.
$table.= '<img src="'.$imgthLink.'1024x768.png" alt="'.$row['name'].' Wallpaper"><strong>'.$row['name'].' Wallpaper</strong><br />';
for($i=0; $i<=10; $i++)
{
if($i==0)
{
$dimensions ='800x600';
}
if($i==1)
{
$dimensions ='1024x768';
}
if($i==2)
{
$dimensions = '1152x864';
}
if($i==3)
{
$dimensions = '1280x800';
}
if($i==4)
{
$dimensions = '1280x960';
}
if($i==5)
{
$dimensions = '1280x1024';
}
if($i==6)
{
$dimensions = '1400x1050';
}
if($i==7)
{
$dimensions = '1440x900';
}
if($i==8)
{
$dimensions = '1600x1200';
}
if($i==9)
{
$dimensions = '1920x1440';
}
if($i==10)
{
$dimensions = '1920x1200';
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $imgLink.$dimensions.'.png');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
$data = curl_exec($ch);
curl_close($ch);
preg_match_all("/HTTP\/1\.[1|0]\s(\d{3})/",$data,$matches);
$code = end($matches[1]);
if(!$data)
{
// echo "file could not be found";
}
else
{
if($code == 200)
{
// echo "file found";
$table .= '<a href="'.$imgLink.$dimensions.'.png">'.$dimensions.'</a><br />';
}
elseif($code == 404)
{
// echo "file not found";
}
}
// $table .= '<a href="'.$imgLink.$dimensions.'.png">'.$dimensions.'</a><br />';
// echo '<img src="'.$imgthLink.$dimensions.'.png">'.$dimensions.'<br />';
}
The only issue it’s that it looks like it does it slowly. Check the other pages and they come out really quick, but if you try the free wallpaper it takes a lot longer.
http://www.iampixels.com/index.php?pagetype=wallpapers
by the way…
some of the girly images were done by a female friend that is learning photoshop. he he he.
we plan to stuff the website with graphics.
If fopen wrappers are enabled on your server then try using file().
if(file('http://l.yimg.com/g/images/home_photo_jam343.jpg')) {
echo "File Exists";
}
one thing you can do, to sorta counteract the slowness of curl’s fetch is using a caching method, smarty is a good framework to use. but that way you only request the images once outta x minutes, the rest of the time it’s cached.
[QUOTE=jwilliam;2341752]If fopen wrappers are enabled on your server then try using file().
if(file('http://l.yimg.com/g/images/home_photo_jam343.jpg')) {
echo "File Exists";
}
[/QUOTE]
fopen has to be open on the recipients server