Display images present on server using PHP -
I need to display images on a web page from the folder on the server I've tried to do it:
$ dir = 'images'; $ File_display = array ('jpg', 'jpeg', 'png', 'gif'); If (file_exists ($ dir) == incorrect) {echo 'directory' ', $ dir,' \ 'not found'; } And {$ dir_contents = scandor ($ dir); As foreign currency ($ Dir_contents $ file) {$ file_type = strtolower (end (explode ( '.', $ File))); If ($ file! == '.' & Amp; $ file! == '..' & amp; amp; in_array ($ file_type, $ file_display) == true) {echo '& lt; Img class = "photo" Src = "', $ dir,' / ', $ file,' alt alt = '', $ file, '/ & gt; '; }}} This is not working, so I made some changes and try to do it:
$ dir = 'images'; $ File_display = array ('jpg', 'jpeg', 'png', 'gif'); If (file_exists ($ dir) == incorrect) {echo 'directory' '' $ Dir. '\' did not get'; } And {$ dir_contents = scandor ($ dir); Foreign currency ($ dir_contents $ as file) {$ file_type = strtolower (end (explosion ('.', $ File))); \\ error if ($ file! == '.' & Amp; $ file! == '..' & amp; amp; in_array ($ file_type, $ file_display) == true) {echo '& lt; Img class = "photo" src = "'. $ Dir." / '. $ File.' "Alt =" '. $ File.' "';'; }}} But there was an error should be passed only variable "by reference", so I tried:
$ dir = 'images '; $ File_display = array ('jpg', 'jpeg', 'png', 'gif'); If (file_exists ($ dir) == incorrect) {echo 'directory' ', $ dir,' \ 'not found'; } And {$ dir_contents = scandor ($ dir); As foreign currency ($ Dir_contents $ file) {$ file_type = strtolower (end (explode ( '.', $ File))); $ Tmp = Explosion ('.', $ File); \\ This line $ file_type = end ($ tmp) changed; \\ If changed this line ($ file! == '.' & Amp; $ file! == '..' & amp; amp; in_array ($ file_type, $ file_display) == true) {echo '& Lt; Img class = "photo" src = "', $ dir,' / ', $ file,'" alt = "', $ file,'" /> '; How any idea to display an image dynamically from server PHP to In my project I will focus on several folders within the image directory is used RecursiveDirectoryIterator and RegexIterator and valid will prepare an array of files (which regularly corresponds to the expression, file extension jpg in our case | jpeg | Png | gif)
& lt ;? Php $ folder = "images '; {$ Directory = New recurring Try Dayrectoriaitretr (Wastvikpth ($ folder)); $ iterator = new recursive iterator iterator ($ directory); $ file = new Regeksitretr ($ iterator, '/ .. + .. (Jepijijijjang. Pijiaijiaiafaai) Antiaai, recursive Rijaksetr GE-Mattisiac);} catch (exception $ e) {echo "invalid directory:". $ E- & gt; getMessage ();} // $ files is an array with file names of all valid images if (isset ($ Files) & amp; $ files! = Null) {foreach ($ filepath = $ gt; $ value $ Files format) {echo "& Lt; Img src = '". $ Filepath."' & Gt; & Lt; Br> ";}}? & Gt;
Hope this helps
Comments
Post a Comment