php reads image files in the directory This article is a PHP code that reads image files in a directory. It uses opendir to open the directory and then obtains the file suffix name to determine whether it is the specified file.
php tutorial to read image files in the directory
This article is a PHP code that reads image files in a directory. It uses opendir to open the directory and then obtains the file suffix name to determine whether it is the specified file.
*/
$directory = 'gallery';
$allowed_types=array('jpg','jpeg','gif','png');
$file_parts=array();
$ext='';
$title='';
$i=0;$dir_handle = @opendir($directory) or die("there is an error with your image directory!");
while ($file = readdir($dir_handle))
{
if($file=='.' || $file == '..') continue;
$file_parts = explode('.',$file);
$ext = strtolower(array_pop($file_parts));$title = implode('.',$file_parts);
';
$title = htmlspecialchars($title);
$nomargin='';
if(in_array($ext,$allowed_types))
{
if(($i+1)%4==0) $nomargin='nomargin';
echo '
$i++;
}
}closedir($dir_handle);