2012-09-27 40 views
0

的結果我發現這是拍攝圖像的目錄,並創建縮略圖淨以下PHP腳本。這部分工作很好,期待我注意到排序關閉。最好的我可以告訴的是它的使用的文件名,我想使用的創建日期,因爲我分類從安全的相機創建的圖像的目錄。排序一個PHP腳本的縮略圖

任何輸入和方向的位(OK,很多)將是巨大的,因爲我沒有很多的PHP經驗,但可以避開一些。再次

感謝您的幫助!

<html><head><title>Snapshots</title></head> 
<body bgcolor='white'> 

<?php 
$folder = '.'; 
$dir = getcwd(); 
DirStat($folder, 0); 
chdir($dir); 
$FolderSize = ByteSize($FolderSize); 
$FileCount=$FileCount-2; 
?> 

<h2 align=center><?php echo date('m/d/Y H:i:s') ." - $FileCount Snapshots - $FolderSize";?></h4> 

<?php 

$imagens=''; 
$dn = opendir('.'); 
while (false !== ($file = readdir($dn))) { 
if ($file == '.' || $file =='..' || $file =='index.php' || $file =='Thumbs.db'){ 
     //print "<a href=$file>$file</a><br>"; 
}else{ 
     if (is_dir($file)){ 
       print "<img src='/imagens/diretorio.png'>&nbsp;<a href='$file?dir=dirname(__FILE__)'>$file</a><br>"; 
     }else{ 
       $tamanho = filesize($file); 
       $m = 'bytes'; // M�ltiplo 
       if ($tamanho>1024) { 
         $tamanho=round($tamanho/1024,2); 
         $m = 'KB'; 
       } elseif($tamanho > 1024*1024){ 
         $tamanho = round(($tamanho/1024)/1024,2); 
         $m = 'MB'; 
       } 

       $imagens .=OutputThumbnail($file, $tamanho, $m); 
     } 
} 
} 

closedir($dn); 

print '<br>'.$imagens; 

function OutputThumbnail($image_file, $tamanho, $m) 
{ 
     if (file_exists($image_file)) 
     { 
       $size = GetImageSize($image_file); 

       if ($size[0] <=64) { 
         $larg=$size[0]; 
       }elseif ($size[0] > 64 && $size[0] <= 200) { 
         $larg=64; 
       }elseif ($size[0] > 201 && $size[0] < 400) { 
         $larg=128; 
       }elseif ($size[0] > 401) { 
         $larg=256; 
       } 

       if ($size[0] == 0) $size[0]=1; 

       $alt= ($larg * $size[1])/$size[0]; 

       return "<a href=$image_file><img width=$larg height=$alt  src=$image_file border=0 
         TITLE='$image_file - $larg x $alt - $tamanho $m'></a>&nbsp;&nbsp;"; 
     } 
} 

?> 

<?php 
function DirStat($directory) { 
     global $FolderCount, $FileCount, $FolderSize; 

     chdir($directory); 
     $directory = getcwd(); 
     if($open = opendir($directory)) { 
       while($file = readdir($open)) { 
         if($file == '..' || $file == '.') continue; 
           if(is_file($file)) { 
             $FileCount++; 
             $FolderSize += filesize($file); 
           } elseif(is_dir($file)) { 
             $FolderCount++; 
           } 
       } 
       if($FolderCount > 0) { 
         $open2 = opendir($directory); 
         while($folders = readdir($open2)) { 
           $folder = $directory.'/'.$folders; 
           if($folders == '..' || $folders == '.') continue; 
             if(is_dir($folder)) { 
               DirStat($folder); 
             } 
           } 
           closedir($open2); 
         } 
         closedir($open); 
       } 
} 

function ByteSize($bytes) { 
     $size = $bytes/1024; 
     if($size < 1024){ 
       $size = number_format($size, 2); 
       $size .= 'KB'; 
     } else { 
       if($size/1024 < 1024) { 
         $size = number_format($size/1024, 2); 
         $size .= 'MB'; 
       } elseif($size/1024/1024 < 1024) { 
         $size = number_format($size/1024/1024, 2); 
         $size .= 'GB'; 
       } else { 
         $size = number_format($size/1024/1024/1024,2); 
         $size .= 'TB'; 
       } 
     } 
     return $size; 
} 

?> 

回答

1

我已經添加了非常骯髒的排序方式(效率不高)。以下行更改爲SORT_DESC或SORT_ASC代碼降序排序或上升。

arraySortByColumn($exifData, 'time', SORT_DESC); 

你添加了排序功能的腳本:

<html><head><title>Snapshots</title></head> 
<body bgcolor='white'> 

<?php 
$folder = '.'; 
$dir = getcwd(); 
DirStat($folder, 0); 
chdir($dir); 
$FolderSize = ByteSize($FolderSize); 
$FileCount=$FileCount-2; 
?> 

<h2 align=center><?php echo date('m/d/Y H:i:s') ." - $FileCount Snapshots - $FolderSize";?></h4> 

<?php 

$imagens=''; 
$exifData = array(); 
$dn = opendir('.'); 
while (false !== ($file = readdir($dn))) { 
if ($file == '.' || $file =='..' || $file =='index.php' || $file =='Thumbs.db'){ 
     //print "<a href=$file>$file</a><br>"; 
}else{ 
     if (is_dir($file)){ 
       print "<img src='/imagens/diretorio.png'>&nbsp;<a href='$file?dir=dirname(__FILE__)'>$file</a><br>"; 
     }else{ 
       $tamanho = filesize($file); 
       $datetime = @exif_read_data($file); 
       $m = 'bytes'; // 
       if ($tamanho>1024) { 
         $tamanho=round($tamanho/1024,2); 
         $m = 'KB'; 
       } elseif($tamanho > 1024*1024){ 
         $tamanho = round(($tamanho/1024)/1024,2); 
         $m = 'MB'; 
       } 
       $exifData[] = array('time' => $datetime['FileDateTime'], 'file' => $file, 'tamanho' => $tamanho, 'm' => $m); 

     } 
} 
} 

closedir($dn); 
//change to SORT_DESC or SORT_ASC 
arraySortByColumn($exifData, 'time', SORT_DESC); 

foreach ($exifData as $value) { 
    $imagens .= OutputThumbnail($value['file'], $value['tamanho'], $value['m']); 
} 

print '<br>'.$imagens; 

function arraySortByColumn(&$arr, $col, $dir = SORT_DESC) { 
     $sort_col = array(); 
     foreach ($arr as $key => $row) { 
      $sort_col[$key] = $row[$col]; 
     } 
     array_multisort($sort_col, $dir, $arr); 
    } 

function OutputThumbnail($image_file, $tamanho, $m) 
{ 
     if (file_exists($image_file)) 
     { 
       $size = GetImageSize($image_file); 

       if ($size[0] <=64) { 
         $larg=$size[0]; 
       }elseif ($size[0] > 64 && $size[0] <= 200) { 
         $larg=64; 
       }elseif ($size[0] > 201 && $size[0] < 400) { 
         $larg=128; 
       }elseif ($size[0] > 401) { 
         $larg=256; 
       } 

       if ($size[0] == 0) $size[0]=1; 

       $alt= ($larg * $size[1])/$size[0]; 

       return "<a href=$image_file><img width=$larg height=$alt  src=$image_file border=0 
         TITLE='$image_file - $larg x $alt - $tamanho $m'></a>&nbsp;&nbsp;"; 
     } 
} 

?> 

<?php 
function DirStat($directory) { 
     global $FolderCount, $FileCount, $FolderSize; 

     chdir($directory); 
     $directory = getcwd(); 
     if($open = opendir($directory)) { 
       while($file = readdir($open)) { 
         if($file == '..' || $file == '.') continue; 
           if(is_file($file)) { 
             $FileCount++; 
             $FolderSize += filesize($file); 
           } elseif(is_dir($file)) { 
             $FolderCount++; 
           } 
       } 
       if($FolderCount > 0) { 
         $open2 = opendir($directory); 
         while($folders = readdir($open2)) { 
           $folder = $directory.'/'.$folders; 
           if($folders == '..' || $folders == '.') continue; 
             if(is_dir($folder)) { 
               DirStat($folder); 
             } 
           } 
           closedir($open2); 
         } 
         closedir($open); 
       } 
} 

function ByteSize($bytes) { 
     $size = $bytes/1024; 
     if($size < 1024){ 
       $size = number_format($size, 2); 
       $size .= 'KB'; 
     } else { 
       if($size/1024 < 1024) { 
         $size = number_format($size/1024, 2); 
         $size .= 'MB'; 
       } elseif($size/1024/1024 < 1024) { 
         $size = number_format($size/1024/1024, 2); 
         $size .= 'GB'; 
       } else { 
         $size = number_format($size/1024/1024/1024,2); 
         $size .= 'TB'; 
       } 
     } 
     return $size; 
} 

?> 
+0

這似乎一直是它!謝謝您的幫助。 – user1704228