English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

okay, I'm not too good with PHP, but I've been trying my best. So far, I have something along the lines of this:


$img1 = "http://www.pic.com/pic.jpg"
$img2 = "default.jpg"

now I want $img1 to load as the image, but should it not be able to load (the hosting server is offline, picture was deleted, etc.) then it will display $img2. I can't seem to put together a workable code, though I think it probably utilizes the "if", or "else" conditions. If at all possible could someone show me what the code is??? I've been up all night trying to figure this out!

2006-09-24 01:21:16 · 2 answers · asked by detroitkid17 2 in Computers & Internet Other - Computers

2 answers

hmm.. thats real problem..
but we could trick it..

you famililiar with html right?
make to put those picture..
set default pic as background of those table (at tag)
and other image using img src

so if other imnage dont show up, the background image will..
:)

but.. im not satisfied with this solution too..

2006-09-24 02:04:50 · answer #1 · answered by deval_agrifarman 6 · 0 0

This should work if you host the image

// file location
$filename = "/pic.jpg";

// default image
$img = "/default.jpg";


// check if file exists
if (file_exists($filename)) {
$img = $filename;
}

?>

if it is a remote file use

function url_exists($url)
{
$handle = @fopen($url, "r");
if ($handle === false)
return false;
fclose($handle);
return true;
}

// file location
$filename = "http://www.pic.com/pic.jpg";

// default image
$img = "/default.jpg";

// check if file exists

if (url_exists($filename)){
$img = $filename;
}
?>

Though hot linking is not cool

2006-09-25 11:03:51 · answer #2 · answered by dt01pqt_pt 2 · 0 0

fedest.com, questions and answers