当前位置:Gxlcms > PHP教程 > php读取目录下图像文件_PHP教程

php读取目录下图像文件_PHP教程

时间:2021-07-01 10:21:17 帮助过:3人阅读

php 读取目录下图像文件 本款是一款php 读取目录下图像文件哦,代码,他利用了opendir来打开目录然后获取文件后缀名,判断是否为指定文件。

php教程 读取目录下图像文件
本款是一款php 读取目录下图像文件哦,代码,他利用了opendir来打开目录然后获取文件后缀名,判断是否为指定文件。
*/

$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 '

'.$title.'
';

$i++;
}
}

closedir($dir_handle);

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/633023.htmlTechArticlephp 读取目录下图像文件本款是一款php 读取目录下图像文件哦,代码,他利用了opendir来打开目录然后获取文件后缀名,判断是否为指定文件...

人气教程排行