I'm using FileField and ImageField together to allow user to upload either a Flash video or an Image File for a particular CCK. I want to use some PHP script in my page script to display images a certain way if they upload an image or display the flash video if they upload a flash video using FileField.

Simply I want to say if there has been a file entered in the FileField than output this code and if they have not entered a file in the FileField than that code is not outputted:

<img src="<?php print $base_path ?><?php print $node->field_page_image[0][filepath] ?>">

Something like

<?php if ($fields['field_page_image']->filepath != '') { ?>
<img src="<?php print $base_path ?><?php print $node->field_page_image[0][filepath] ?>">
<?php } ?>

I know that if statement is not correct but hoping that gets across the idea I am trying to achieve.

Comments

quicksketch’s picture

My preference is to check the "fid" (File ID) property when checking for an empty file. It will be either 0 or not exist at all if there is no file attached.

<?php if ($node->field_page_image[0]['fid']): ?>
<img src="<?php print $base_path . $node->field_page_image[0]['filepath'] ?>" />
<?php endif; ?>
gt2001’s picture

Perfect. Exactly what I needed. Thank you!

quicksketch’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.