織夢站內(nèi)選擇圖片排序是直接read()讀取直接輸出,如果我們同一時間上傳了多個圖片,在沒有經(jīng)過排序的情況下,我們?nèi)ミx擇圖片很難快速分辨哪個是剛剛上傳的,解決方法是讀取該目錄的文件列表,用"文件名、修改時間"做鍵值對,塞入數(shù)組,注意,是用文件名做鍵,因為圖片有可能是同一個時分秒上傳的,并且沒有毫秒,我們無法判斷哪個是快一秒哪個慢一秒。再對"修改時間"倒序,最后foreach輸出即可。
打開 include/dialog/select_images.php 找到
$dh = dir($inpath);
....(中間代碼省略)
$dh->close();
146行到245行,把整個代碼換成下面的代碼
$dh = dir($inpath);
$ty1="";
$ty2="";
$filearr = array();
while($file = $dh->read()) {
//-----計算文件大小和創(chuàng)建時間
if($file!="." && $file!=".." && !is_dir("$inpath/$file")){
$filetime = filemtime("$inpath/$file");
$filetime = MyDate("Y-m-d H:i:s", $filetime);
$filearr[] = $file;
$filetimearr[] = $filetime;
}
if($file == ".") continue;
else if($file == "..")
{
if($activepath == "") continue;
$tmp = preg_replace("#[/][^/]*$#i", "", $activepath);
$line = "
<tr>
<td class='linerow' colspan='2'>
<a href='select_images.php?imgstick=$imgstick&v=$v&f=$f&activepath=".urlencode($tmp).$addparm."'><img src=img/dir2.gif border=0 width=16 height=16 align=absmiddle>上級目錄</a></td>
<td colspan='2' class='linerow'> 當前目錄:$activepath</td>
</tr>
";
echo $line;
}
else if(is_dir("$inpath/$file"))
{
if(preg_match("#^_(.*)$#i", $file)) continue; #屏蔽FrontPage擴展目錄和linux隱蔽目錄
if(preg_match("#^.(.*)$#i", $file)) continue;
$dirarr[] = $file;
}
}//End Loop
$dh->close();
arsort($dirarr);
foreach($dirarr as $file)
{
$line = "
<tr>
<td bgcolor='#F9FBF0' class='linerow' colspan='2'>
<a href='select_images.php?imgstick=$imgstick&v=$v&f=$f&activepath=".urlencode("$activepath/$file").$addparm."'><img src=img/dir.gif border=0 width=16 height=16 align=absmiddle>$file</a></td>
<td class='linerow'> </td>
<td bgcolor='#F9FBF0' class='linerow'> </td>
</tr>";
echo "$line";
}
array_multisort($filetimearr,SORT_DESC,SORT_STRING, $filearr);
array_multisort($filetimearr,SORT_DESC,SORT_STRING, $filetimearr);
$result = array_combine($filearr,$filetimearr);
foreach($result as $file => $filetime)
{
$filesize = filesize("$inpath/$file");
$filesize = $filesize / 1024;
if($filesize != "")
if($filesize < 0.1){
@list($ty1, $ty2) = split(".", $filesize);
$filesize = $ty1.".".substr($ty2, 0, 2);
}
else{
@list($ty1, $ty2) = split(".", $filesize);
$filesize = $ty1.".".substr($ty2, 0, 1);
}
if(preg_match("#.(gif|png)#i", $file))
{
$reurl = "$activeurl/$file";
$reurl = preg_replace("#^..#", "", $reurl);
if($cfg_remote_site=='Y' && $remoteuploads == 1)
{
$reurl = $remoteupUrl.$reurl;
}else{
$reurl = $reurl;
}
if($file==$comeback) $lstyle = " style='color:red' ";
else $lstyle = "";
$line = "
<tr>
<td align='center' class='linerow' bgcolor='#F9FBF0'>
<a href="#" onClick="ChangeImage('$reurl');"><img src='img/picviewnone.gif' width='16' height='16' border='0' align=absmiddle></a>
</td>
<td class='linerow' bgcolor='#F9FBF0'>
<a href=# onclick="ReturnImg('$reurl');" $lstyle><img src=img/gif.gif border=0 width=16 height=16 align=absmiddle>$file</a></td>
<td class='linerow'>$filesize KB</td>
<td align='center' class='linerow' bgcolor='#F9FBF0'>$filetime</td>
</tr>";
echo "$line";
}
else if(preg_match("#.(jpg)#i", $file))
{
$reurl = "$activeurl/$file";
$reurl = preg_replace("#^..#", "", $reurl);
if($cfg_remote_site=='Y' && $remoteuploads == 1)
{
$reurl = $remoteupUrl.$reurl;
}else{
$reurl = $reurl;
}
if($file==$comeback) $lstyle = " style='color:red' ";
else $lstyle = "";
$line = "
<tr>
<td align='center' class='linerow' bgcolor='#F9FBF0'>
<a href="#" onClick="ChangeImage('$reurl');"><img src='img/picviewnone.gif' width='16' height='16' border='0' align=absmiddle></a>
</td>
<td class='linerow' bgcolor='#F9FBF0'>
<a href=# onclick="ReturnImg('$reurl');" $lstyle><img src=img/jpg.gif border=0 width=16 height=16 align=absmiddle>$file</a>
</td>
<td class='linerow'>$filesize KB</td>
<td align='center' class='linerow' bgcolor='#F9FBF0'>$filetime</td>
</tr>";
echo "$line";
}
}
打開 dede/templets/templets_default.htm 找到
$dh = dir($templetdird);
改成
$files = scandir($templetdird);
繼續(xù)找到
while($filename=$dh->read())
改成
foreach($files as $filename)
完成
版權(quán)聲明: 本站資源均來自互聯(lián)網(wǎng)或會員發(fā)布,如果侵犯了您的權(quán)益請與我們聯(lián)系,我們將在24小時內(nèi)刪除!謝謝!
轉(zhuǎn)載請注明: 織夢站內(nèi)選擇文件夾和圖片文件排序后臺模板管理按名稱排序