我有这个代码设置插入任何图像上传到我的“图像”文件夹,右进入我有一个画廊....我的问题是,它的种类随机插入..我想将其设置为将最近上传的图片插入图库“行”的末尾,有什么建议?由于自动图片库插入
<?php
$image_dir = 'uploads/images/';
$per_column = 10;
if ($handle = opendir($image_dir)) {
while (false !== ($file = readdir($handle)))
{
if ($file != '.' && $file != '..')
{
if(strstr($file,'.png'))
{
$files[] = $file;
}
if(strstr($file,'.jpg'))
{
$files[] = $file;
}
if(strstr($file,'.gif'))
{
$files[] = $file;
}
if(strstr($file,'.jpeg'))
{
$files[] = $file;
}
}
}
closedir($handle);
}
if(count($files))
{
foreach($files as $file)
{
$count++;
echo '<li><img src="',$image_dir,$file,'" width="20" height="20" title="',$file,'"/></li>';
if($count % $per_column == 0) { echo '<div class="clear"></div>'; }
}
}
else
{
echo 'no pictures yet...';
}
?>
这太好了,但是相反的,最新的图片插入前台,我希望它从最后一个点开始,从左到右,你的代码插入第一个点并将其余部分往下碰。 – tcd
使用ksort(krsort是反向)。这个想法是使用数组的密钥作为上传的时间。然后你按键排列数组。 –
啊完美,谢谢! – tcd