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
Post a Comment