好的,我对 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.';
}
}
}