Forum Moderators: coopster

Message Too Old, No Replies

Unexpected T ECHO, trying to use 'echo' in 'if'

echo inside if statement

         

rigidkitchen

5:39 pm on Oct 28, 2009 (gmt 0)

10+ Year Member



I'm trying to dynamically call a gallery name for a if(file_exists) statement in order to have a dynamically-loaded header image for a gallery

Here is my code:


<?php if (file_exists( $_SERVER{'DOCUMENT_ROOT'} . "/wp-content/gallery/galleryheader/".echo $gallery->ID."-headerthmb.jpg")){ ?>

Should I be setting a variable for the echo statement before I run the if (file_exists) clause?

'DOCUMENT_ROOT' points to the public_html directory in my actual code.

Thanks for any help or suggestions, this is really frustrating

EDIT: Here is the rest of my code for context:

<div id="gallery_<?php echo $gallery->ID ?>" class="gallery">

<?php
if (file_exists( $_SERVER{'/home/rigidkit/public_html'} . "/wp-content/gallery/galleryheader/".echo $gallery->ID."-headerthmb.jpg")){ ?>
<div id="gallery_<?php echo $gallery->ID ?>"_header" class="gallery_header">
<a rel="shadowbox[%GALLERY_NAME%]" href="http://rigidkitchen.net/wp-content/gallery/galleryheader/<?php echo $gallery->ID ?>-header.jpg">
<img src="http://rigidkitchen.net/wp-content/gallery/galleryheader/<?php echo $gallery->ID ?>-headerthmb.jpg" title="" alt="" />
</a>
</div>
<?php } else { ?>
<div id="gallery_<?php echo $gallery->ID ?>_header" class="gallery_header">
<!-- No Gallery Header Image Found -->
</div>
<?php }
?>

rigidkitchen

6:43 pm on Oct 28, 2009 (gmt 0)

10+ Year Member



Can't edit, so I'll add this as a new post:

I need some way to correlate the correct gallery header image with the correct gallery. Is there an easy way to do this?

londrum

6:54 pm on Oct 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



you could just do something like this and that will probably fix it

$filename = $_SERVER['DOCUMENT_ROOT']."/wp-content/gallery/galleryheader/".$gallery->ID."-headerthmb.jpg";

if(file_exists($filename)) { blah; }

rigidkitchen

10:02 pm on Oct 28, 2009 (gmt 0)

10+ Year Member



Yep! That did it. Thanks!

I also noticed I had put a test file in the folder with the correct filename, only to realize later that it was a .gif

>_<

TheMadScientist

11:28 pm on Oct 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just a quick note, even though it's working now:
You were also using braces instead of brackets.

Incorrect:
$_SERVER{'DOCUMENT_ROOT'}

Correct:
$_SERVER['DOCUMENT_ROOT']