how to work with directory in php -


the code is

<?php $files = array();   $dir = opendir('/xampp/htdocs/myfun/template/home');   while(($file = readdir($dir)) !== false) {     if($file !== '.' && $file !== '..') {           $files[] = $file;     } }   closedir($dir);   //sort($files); $i=0;  foreach($files $key) {     echo "<iframe align='center' width='100%' height='605px' src='$key' title='$files[$i]'></iframe>";     break; } ?> 

i want show templates onclick next/prev button.horizontally. slider. please help

correct logic iterate directory in while loop false != ($file = readdir($dir)), assign file name first , check it's not false.

also can print title $key itself. $files[$i] , $i variable not required.

in order iterate through files of directory remove break, cause end loop after first iteration.

<?php $files = array(); $dir = opendir('/xampp/htdocs/myfun/template/home'); while(false != ($file = readdir($dir))) {     if($file !== '.' && $file !== '..')     {         $files[] = $file;     } } closedir($dir); //sort($files);  foreach($files $key) {     echo "<iframe align='center' width='100%' height='605px' src='$key' title='$key'></iframe>"; } ?> 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -