php - automatic image gallery insert -
I have this code to insert any image uploaded in the "image" folder, which I have in the gallery ... my problem is that it involves them randomly .. I would like to set it up to include the most recently uploaded photo at the end of the gallery "row", any suggestions? Thanks
& lt ;? Php $ image_dir = 'Upload / Image /'; $ Per_column = 10; If ($ handle = opendir ($ image_dir)) {while (false! == ($ file = readdir ($ handle))) {if ($ file! = '.' & Amp; $ file! = '..' ) {If (strstr ($ file, '.png')) {$ files [] = $ file; } If (strstr ($ file, '.jpg')) {$ files [] = $ file; } If (strust ($ file, .gif ')) {$ files [] = $ file; } If (strust ($ file, '.jpeg')) {$ files [] = $ file; }}} Closed ($ handle); } If (counting ($ files)) {foreach ($ files as files $) {$ count ++; Copy; Li & gt; & Lt; Img src = "', $ image_dir, $ file,'" width = "20" height = "20" title = "', $ file," / / gt; & Lt; / Li & gt; '; If ($ count% $ per_column == 0) {echo '& lt; Div class = "clear" & gt; & Lt; / Div & gt; '; }}} Else {echo "There is no picture yet ..."; }? & Gt;
& lt; Php $ image_dir = 'Upload / Image /'; $ Per_column = 10; $ ValidExt = array ('png' = & gt; 'image / png', 'jpeg' => image / jpeg ',' jpg '=>' image / jpg ',' gif '= & gt; 'Image / gif'); If ($ handle = opendir ($ image_dir)) {while (false! == ($ file = readdir ($ handle))} {$ ext = strtolower (substr ($ file, -3)); If (isset ($ validExt [$ ext])) {$ stats = stat ($ image_dir. $ File); $ Files [$ stats ['mtime']] = $ file; }} Close ($ handle); } $ Count = 0; Krsort ($ files); $ Cnt = count ($ files); If ($ cnt) {foreach (files $ $ as file) {$ count ++; Copy; Li & gt; & Lt; Img src = "'. $ Image_dir. $ File." "Width =" 20 "height =" 20 "heading =" ' Substr ($ file, 0, -4). '' /></li>'.chr(10); If ($ count% $ per_column == 0) {echo '& lt; Div class = "clear" & gt; & Lt; / Div & gt; '; }}} Else {echo "There is no picture yet ..."; }
Comments
Post a Comment