Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/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_Gallery - Fatal编程技术网

按文件名排序PHP库

按文件名排序PHP库,php,gallery,Php,Gallery,我的PHP有点不稳定,我尝试过natsort和scandir,但可能我没有正确使用它们,无论如何,我需要这个PHP脚本来按顺序显示图像-任何帮助都会非常明显。提前谢谢 /** settings **/ $images_dir = 'preload-images-hair/'; $thumbs_dir = 'preload-images-hair-thumbs/'; $thumbs_width = 200; $images_per_row = 4; /** generate photo gall

我的PHP有点不稳定,我尝试过natsort和scandir,但可能我没有正确使用它们,无论如何,我需要这个PHP脚本来按顺序显示图像-任何帮助都会非常明显。提前谢谢

/** settings **/
$images_dir = 'preload-images-hair/';
$thumbs_dir = 'preload-images-hair-thumbs/';
$thumbs_width = 200;
$images_per_row = 4;

/** generate photo gallery **/
$image_files = get_files($images_dir);
if(count($image_files)) {
$index = 0;
foreach($image_files as $index=>$file) {
    $index++;
    $thumbnail_image = $thumbs_dir.$file;
    if(!file_exists($thumbnail_image)) {
        $extension = get_file_extension($thumbnail_image);
        if($extension) {
            make_thumb($images_dir.$file,$thumbnail_image,$thumbs_width);
        }
    }
    echo '<a href="',$images_dir.$file,'" data-lightbox-gallery="gallery" class="lightbox" rel="gallery"><img src="',$thumbnail_image,'" /></a>';
    if($index % $images_per_row == 0) { echo '<div class="clear"></div>'; }
}
echo '<div class="clear"></div>';
}
else {
echo '<p>There are no images in this gallery.</p>';
 }
/**设置**/
$images_dir='preload images hair/';
$thumbs_dir='preload images hair thumbs/';
$thumbs_width=200;
$images\u/行=4;
/**生成照片库**/
$image\u files=获取文件($images\u dir);
如果(计数($image_文件)){
$index=0;
foreach($index=>$file形式的图像文件){
$index++;
$thumbnail\u image=$thumbs\u dir.$file;
如果(!file_存在($thumbnail_image)){
$extension=get_file_extension($thumbnail_image);
如果($延期){
制作拇指($images\u dir.$file、$thumbnail\u image、$thumbs\u width);
}
}
回声';
如果($index%$images_per_row==0){echo';}
}
回声';
}
否则{
echo“此库中没有图像。

”; }
您的
$index++
似乎有误,您可能可以将其删除。运行
get_files
(我假设它返回一个文件名数组)后,对该结果运行

$image_files = get_files($images_dir);
sort($image_files);

你想要什么样的顺序?从目录中读取时,文件通常按创建时间排序。请按文件名排序