Test for image upload first
3 posts by 2 authors in: Forums > CMS Builder
Last Post: April 11, 2012 (RSS)
By furcat - March 29, 2012
I am using code shown below where I have a section editor/page where I allow my customer to upload multiple images for a page.
<h3>Additional Photos</h3>
<p>Click on a thumbnail shown below for a larger image.</p>
<?php foreach ($ecofuelRecord['additional_photos'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<a href="<?php echo $upload['urlPath'] ?>"><img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /></a>
<?php else: ?>
<h3>No photos for this page</h3>
<?php endif ?>
<?php endforeach ?>
However, I would like to test first to see if an image has actually been uploaded before I put the text about "Additional Photos" on the page. I don't like the way it looks to have a heading about additional items if none in fact exist.
So, how do I test to see if an image has been uploaded before the foreach statement?
Thanks!
<h3>Additional Photos</h3>
<p>Click on a thumbnail shown below for a larger image.</p>
<?php foreach ($ecofuelRecord['additional_photos'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<a href="<?php echo $upload['urlPath'] ?>"><img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /></a>
<?php else: ?>
<h3>No photos for this page</h3>
<?php endif ?>
<?php endforeach ?>
However, I would like to test first to see if an image has actually been uploaded before I put the text about "Additional Photos" on the page. I don't like the way it looks to have a heading about additional items if none in fact exist.
So, how do I test to see if an image has been uploaded before the foreach statement?
Thanks!
Re: [furcat] Test for image upload first
By rconring - March 29, 2012
I think this is what you want.
Use a conditional to check if uploads exist:
<?php if ($ecofuelRecord['additional_photos']): ?>
Put your display code here .....
<?php endif ?>
Use a conditional to check if uploads exist:
<?php if ($ecofuelRecord['additional_photos']): ?>
Put your display code here .....
<?php endif ?>
Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987
Re: [rconring] Test for image upload first
By furcat - April 11, 2012
Perfect. Exactly what I needed. Thank you.