好吧,我对php很陌生,我的问题可能非常愚蠢,但我已经尝试了我能想到的所有组合,不能让它正常工作
它要么在空图库中根本不显示消息,要么在每个图库中显示三次,而不管它是否包含图像。
我知道缩略图的周长不是最理想的,但是我试过在自动图像裁剪周长中工作来创建缩略图,但是我不能让它为我的生活工作。
我主要关心的是现在空的画廊消息,但如果你能帮助我合并一个可靠的图像裁剪片段,以创建更好的缩略图..请这样做:)
function lightbox_display($dir_to_search, $rel){
$image_dir = $dir_to_search;
$dir_to_search = scandir($dir_to_search);
$image_exts = array('gif', 'jpg', 'jpeg', 'png');
$excluded_filename = '_t';
foreach ($dir_to_search as $image_file){
$dot = strrpos($image_file, '.');
$filename = substr($image_file, 0, $dot);
$filetype = substr($image_file, $dot+1);
$thumbnail_file = strrpos($filename, $excluded_filename);
if ((!$thumbnail_file) and array_search($filetype, $image_exts) !== false){
echo "<a href='".$image_dir.$image_file."' rel='".$rel."'>
<img src='".$image_dir.$image_file."' alt='".$filename."' width='100' height='80' title='' border='none'/>
</a>"."'n";
} else {
echo 'Currently there are no machines available for sale, please check back with us soon.';
}
}
}
更新php代码:
我尝试添加一个数组到$imagesFound,以排除可能包含的文件夹服务器端。
function lightbox_display($dir_to_search, $rel){
$image_dir = $dir_to_search;
$dir_to_search = scandir($dir_to_search);
$image_exts = array('gif', 'jpg', 'jpeg', 'png');
$excluded_filename = '_t';
$imagesFound = array('gif', 'jpg', 'jpeg', 'png') && 0;
foreach ($dir_to_search as $image_file){
$dot = strrpos($image_file, '.');
$filename = substr($image_file, 0, $dot);
$filetype = substr($image_file, $dot+1);
$thumbnail_file = strrpos($filename, $excluded_filename);
if ((!$thumbnail_file) && array_search($filetype, $image_exts) !== false) {
$imagesFound++;
echo "<a href='$image_dir$image_file' rel='$rel'>
<img src='$image_dir$image_file' alt='$filename' width='100' height='80' title='' border='none'/>
</a>'n";
}
if ((0 === $imagesFound) !== true){
echo 'Currently there are no machines available for sale, please check back with us soon.';
}
}
}
如果它显示相同的消息三次,我假设$dir_to_search
中有三个文件,但没有一个是图像。它们可能是.
..
或者别的什么。似乎每次找到一个不是有效图像的文件时,都会输出消息,因此您可以做的是计算找到了多少图像,如果没有找到则只输出文本。例如
$imagesFound = 0;
foreach ($dir_to_search as $image_file){
$dot = strrpos($image_file, '.');
$filename = substr($image_file, 0, $dot);
$filetype = substr($image_file, $dot+1);
$thumbnail_file = strrpos($filename, $excluded_filename);
if ((!$thumbnail_file) and array_search($filetype, $image_exts) !== false) {
$imagesFound++;
echo "<a href='$image_dir$image_file' rel='$rel'>
<img src='$image_dir$image_file' alt='$filename' width='100' height='80' title='' border='none'/>
</a>'n";
}
}
if (0 === $imagesFound) {
echo 'Currently there are no machines available for sale, please check back with us soon.';
}
对下面评论的更新:
如果你多次调用lightbox_display(),并且仍然只希望消息显示一次,你可以返回找到的图像的数量并使用它。像这样:
function lightbox_display($dir_to_search, $rel) {
$imagesFound = 0;
foreach ($dir_to_search as $image_file){
if ((!$thumbnail_file) and array_search($filetype, $image_exts) !== false) {
$imagesFound++;
echo "<img...";
}
}
return $imagesFound;
}
$totalImagesFound = 0;
foreach ($galleries as $gallery) {
$totalImagesFound += lightbox_display($gallery['dir'], $rel);
}
if (0 === $totalImagesFound ) {
echo 'Currently there are no machines available for sale, please check back with us soon.';
}
也许会有帮助,虽然不了解你的系统,我真的不知道。