Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP缩略图脚本的排序结果_Php_Date_Sorting_Thumbnails_Creation - Fatal编程技术网

PHP缩略图脚本的排序结果

PHP缩略图脚本的排序结果,php,date,sorting,thumbnails,creation,Php,Date,Sorting,Thumbnails,Creation,我在网上找到了下面的PHP脚本,它正在获取图像目录并创建缩略图。这部分工作得很好,希望我注意到排序已关闭。我能说的最好的是它使用的是文件名,我想使用创建日期,因为我正在排序从安全摄像头创建的图像目录 任何输入和一点(好的,很多)的指导都会很好,因为我没有很多PHP经验,但可以四处走动 再次感谢你的帮助 <html><head><title>Snapshots</title></head> <body bgcolor='white'

我在网上找到了下面的PHP脚本,它正在获取图像目录并创建缩略图。这部分工作得很好,希望我注意到排序已关闭。我能说的最好的是它使用的是文件名,我想使用创建日期,因为我正在排序从安全摄像头创建的图像目录

任何输入和一点(好的,很多)的指导都会很好,因为我没有很多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;
}

?>
快照

我添加了一种非常肮脏的排序方式(效率不高)。在代码中,将行下方更改为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;
}

?>
快照

似乎就是这样!谢谢你的帮助。