PHP If checking for Uploads not working with PHP 8

6 posts by 2 authors in: Forums > CMS Builder
Last Post: August 15, 2022   (RSS)

By pacolvin - August 15, 2022

I'm sure there is an easy fix to this, but I was not able to find anything in the PHP Manual or other places I searched.

On one of my pages I am testing to see if there are any photos in the uploads for the section.  If there are, it displays their thumbnails.  If not, it just does not show anything. Below is the code that I'm using.  It works fine on PHP 7.4, but if I switch to 8, it throws an error and nothing on the page after the error will display.

The culprit seems to be the :None in the first If statement.  Works fine in 7.4, but not 8.  I've tried using the empty() or isset() functions, but I'm not doing something right.

                                <div class="photo-gallery">
                                    <div class="row photos" style="padding-bottom: 20px;">
                                        <?php if (!$record['photos']):None ?>
                                        <?php else: ?>
                                            <?php foreach ($record['photos'] as $index => $upload): ?>
                                                <?php if ($index >= 4) { continue; } // limit uploads shown ?>
                                                <div class="col-sm-6 col-md-4 col-lg-3 item">
                                                    <a href="<?php echo htmlencode($upload['urlPath']) ?>" data-lightbox="photos<?php echo htmlencode($record['num']) ?>"><img class="img-fluid" src="<?php echo htmlencode($upload['urlPath']) ?>"/></a>
                                                </div>                                                 
                                            <?php endforeach ?>
                                        <?php endif ?> 
                                    </div>
                                </div>

Thanks in advance for any help...

Phil

Hey Phil,

Have you tried just deleting the None?

If hat doesn't work, how about using an elseif instead of the else in the second half.

One of those might work.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

There's both a ! and a None in that line I'm not sure, but that seems to be a double negative.

Try reversing the logic. IE if records then show records, else if !records leave it blank

                                <div class="photo-gallery">
                                    <div class="row photos" style="padding-bottom: 20px;">
                                        <?php if ($record['photos']):?>
<?php foreach ($record['photos'] as $index => $upload): ?>
                                                <?php if ($index >= 4) { continue; } // limit uploads shown ?>
                                                <div class="col-sm-6 col-md-4 col-lg-3 item">
                                                    <a href="<?php echo htmlencode($upload['urlPath']) ?>" data-lightbox="photos<?php echo htmlencode($record['num']) ?>"><img class="img-fluid" src="<?php echo htmlencode($upload['urlPath']) ?>"/></a>
                                                </div>                                                 
                                            <?php endforeach ?>
                                       <?php elseif (!$record['photos']):?>&nbsp;                                            
                                        <?php endif ?> 
                                    </div>
                                </div>
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By pacolvin - August 15, 2022

When I deleted the None previously, I also deleted the : which is what broke the page.  Keeping the : at the end of the IF statement and removing the None works on PHP 7.4 and 8.

Thanks for the suggestions.

Phil

Glad you got it working.

Have you checked out the CMSB Cookbook?

Free trial with the link below

Jerry Kornbuth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php