php - Concise method of using file_exists for a range of filenames -
i using file_exists determine whether image files in specified directory, , if are, displaying them within image rotator. works fine code seems long winded achieves. there better way?
at moment have:
<?php if (file_exists($reg_photo_1_f)) { echo "<li>"; echo "<a href=". $reg_photo_1_f .">"."</a>"; echo "</li>"; } if (file_exists($reg_photo_2_f)) { echo "<li>"; echo "<a href=". $reg_photo_2_f .">"."</a>"; echo "</li>"; } if (file_exists($reg_photo_3_f)) { echo "<li>"; echo "<a href=". $reg_photo_3_f .">"."</a>"; echo "</li>"; } if (file_exists($reg_photo_4_f)) { echo "<li>"; echo "<a href=". $reg_photo_4_f .">"."</a>"; echo "</li>"; } if (file_exists($reg_photo_5_f)) { echo "<li>"; echo "<a href=". $reg_photo_5_f .">"."</a>"; echo "</li>"; } ?>
where each $reg_photo_x_f image path. i'm hoping there way can adapt code can loop until images found exist. image names hashes generated page, not consecutive.
the page creating hashes combines value relevant page in form of php variable pre-defined 'salt' image name matched in same way matching hashed password in database etc. example, $reg_photo_1_f have code on same page:
$reg_photo_1 = sha1("$bh".photo_reg_1); $reg_photo_1_f = $reg_photo_root.$reg_photo_1.".jpg";
...where $bh variable relevant page user on , photo_reg_1 'salt'.
sure there better way name images simplest way think of work dynamic pages.
<?php $files = glob('*.jpg'); foreach($files $file) { echo "<li>"; echo "<a href=". $file.">"."</a>"; echo "</li>"; } ?>
Comments
Post a Comment