Jump to content

[SOLVED] help to Find an image and if there is not one show this one


fubarur

Recommended Posts

I need help on a bit of code to look in a folder and see if there is a image with a certain name, if there is not one display this image instead.

 

The details

 

looking into this folder

/images/event/XX/images/    XX is $id so it is a variable depending on the event you are looking at.

 

The image name

header_1.jpg

 

else if it can not find the above load this default image

/images/event_header.jpg

 

Any help or pointers would be appreciated.

 

I'm sure this is a noob type question, but I'm learning and this is one great resource!

if (file_exists("http://whatever"))

 

{

//do this

}

else

{

//do that

}

 

 

 

I tried this and it did not work?

 

						<?php


if (file_exists("<?=Environment::webroot()?>/images/event/$id/images/header_1.jpg"))

{
<img border="0" src="<?=Environment::webroot()?>/images/event/$id/images/header_1.jpg>" /> 
}
else
{
<img border="0" src="<?=Environment::webroot()?>/images/header_1.jpg>" /> 
}


?>	



hmmm not sure about the code thing going on there...BUT

 

you have not escaped your php

 

if (file_exists("<?=Environment::webroot()?>/images/event/$id/images/header_1.jpg"))

 

{?>

<img border="0" src="<?=Environment::webroot()?>/images/event/$id/images/header_1.jpg>" />

<?}

else

{?>

<img border="0" src="<?=Environment::webroot()?>/images/header_1.jpg>" />

<?}

 

 

?>

@fubarur: you've got the syntax wrong. try:

if (file_exists("/images/event/$id/images/header_1.jpg"))

 

@willpower: good to know =)

 

This gave me a blank page like the last one did

 

							<?php


if (file_exists("/images/event/$id/images/header_1.jpg"))

{
<img border="0" src="<?=Environment::webroot()?>/images/event/$id/images/header_1.jpg>" /> 
}
else
{
<img border="0" src="<?=Environment::webroot()?>/images/header_1.jpg>" /> 
}


?>

 

With the above code removed page loads fine

<?php

if (file_exists("/images/event/$id/images/header_1.jpg")) {
echo"<img border='0' src='<?php Environment: :webroot()?>/images/event/$id/images/header_1.jpg'></img>>"; 
}else{
echo"<img border='0' src='<?php Environment: :webroot()?>/images/header_1.jpg'></img>";
}
?>

read my post!

 

i gave you code and you dont seem to have used it.  You have PHP and HTML mixed together.

 

 

Ok, I think this is what you are talking about, but I used this code below and get a blank page?

 

<?php
if (file_exists("/images/events/$id/images/header_1.jpg"))
?>
<img border="0" src="<?=Environment::webroot()?>/images/events/$id/images/header_1.jpg">
<?php
else;
?>
<img border="0" src="<?=Environment::webroot()?>/images/header.jpg">

 

 

 

 

 

 

 

 

 

 

<?php

if (file_exists("/images/event/$id/images/header_1.jpg")) {
echo"<img border='0' src='<?php Environment: :webroot()?>/images/event/$id/images/header_1.jpg'></img>>"; 
}else{
echo"<img border='0' src='<?php Environment: :webroot()?>/images/header_1.jpg'></img>";
}
?>

 

Your code

<?php

if (file_exists("/images/events/$id/images/header_1.jpg")) {
echo"<img border='0' src='/images/events/$id/images/header_1.jpg'></img>>"; 
}else{
echo"<img border='0' src='images/header.jpg'></img>";
}
?>	

 

Gives me a page but its not finding the image, and its there?

Good news! After looking at all your help I messed around with the code and got it to work!

 

if (file_exists("/var/www/html/images/events/$id/images/header_1.jpg")) {
echo"<img border='0' src='/images/events/$id/images/header_1.jpg'></img>"; 
}else{
echo"<img border='0' src='images/header.jpg'></img>";
}
?>	

 

Thanks for all your help and guidance!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.