How to batch add images with similar name using jquery/ php -
i'm adding images website amount want add together take long time, there quicker way of adding these images , automatically find new images if file name appended +1 such image1.jpg, image2.jpg etc.
i using php. thought maybe done using javascript or jquery loop, loop maybe, im unsure how.
<img src="images/other/pic2.png"></a> <img src="images/other/pic3.png"></a> <img src="images/other/pic4.png"></a> <img src="images/other/pic5.png"></a> <img src="images/other/pic6.png"></a> <img src="images/other/pic7.png"></a> <img src="images/other/pic8.png"></a>
its not thought blindly loop curtain amount of iterations hoping file there , valid file, improve way loop directory of files, check file first valid image , contains expected filename prefix. way can add together may images dir knowing there added without changing code.
<?php $img_path = './images/other/'; $prefix = 'img'; if ($fh = opendir($img_path)) { while (false !== ($file = readdir($fh))) { if ($file != "." && $file != "..") { //validate image , size, check image filename starts $prefix $attr = getimagesize($img_path.$file); if(isset($attr[3]) && substr($file,0,strlen($prefix)) == $prefix){ echo '<img src="'.$img_path.$file.'" '.$attr[3].' alt="'.$file.'"/>'; } } } closedir($fh); } ?>
php jquery image
No comments:
Post a Comment