如何分类图像 [英] How Can I Sort Images
本文介绍了如何分类图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我有这段代码可以显示文件夹中的图像.如何分类图像?我想要最新添加的文件来显示冷杉.谢谢.
Hello, i have this code to show images from a folder. How can i sort the images? i''d like the latest added file to show firs. Thank you.
<?php
$directory = 'server/php/files/';
$thumbsdir = 'server/php/files/thumbnail';
$allowed_types=array('jpg','jpeg','gif','png');
$file_parts=array();
$ext='';
$title='';
$i=0;
$files = scandir($directory); foreach($files as $file)
{
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 '
<div class="pic '.$nomargin.'" style="background:removed('.$thumbsdir.'/'.$file.') no-repeat 50% 50%; margin-removed19px;">
<a href="'.$directory.'/'.$file.'" title="'.$title.'" target="_blank">'.$title.'</a>
</div>';
$i++;
}
}
closedir($dir_handle);
?>
推荐答案
目录 = server/php/files/';
directory = 'server/php/files/';
thumbsdir = '
thumbsdir = 'server/php/files/thumbnail';
allowed_types = array( jpg', jpeg', gif', png');
allowed_types=array('jpg','jpeg','gif','png');
这篇关于如何分类图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文