0
我只有php的基本技能,而且我不得不在网站上放置照片画廊。由于这个网站将被那些对编程知之甚少的人使用,我想要一个简单的使用方法:上传一个带有照片的文件夹(编辑:通过FTP),照片库缩略图会自动显示,点击缩略图会显示满大小的图像。PHP/GD - 画廊中的照片缩略图:随机显示
我使用了一个脚本,可以即时生成缩略图。如果我直接在浏览器中调用它,该脚本似乎工作正常。我获得了我的缩略图。但是当我在页面中显示一个图库时,每个图像源都是对我的脚本的调用,只显示缩略图的一个随机子集,其他图标只显示alt文本。例如,在一个8的画廊,我第一次显示的页面,我可能只得到3,4和7,并刷新后1,3,5,6,8:
我可以找到没有错误信息给出由其他大拇指不加载,但在这里我的PHP的基本技能可能会失败我,也许我只是没有kow在哪里可以找到这样的错误信息。
这里是调用我的脚本:
<a href="resources/galleries/example.jpg"><img src="mini.php?f=example.jpg" alt="Photo" /></a>
和mini.php使用GD:
<?php
$ratio = 150;
$dir = './resources/galleries';
if (!isset($_GET['f'])) {
header('location: index.php');
exit();
}
else {
$image = $_GET['f'];
$tableau = @getimagesize($dir.'/'.$image);
if ($tableau == FALSE) {
header('location: index.php');
exit();
}
else {
// if jpeg
if ($tableau[2] == 2) {
$src = imagecreatefromjpeg($dir.'/'.$image);
if ($tableau[0] > $tableau[1]) {
$im = imagecreatetruecolor(round(($ratio/$tableau[1])*$tableau[0]), $ratio);
imagecopyresampled($im, $src, 0, 0, 0, 0, round(($ratio/$tableau[1])*$tableau[0]), $ratio, $tableau[0], $tableau[1]);
}
else {
$im = imagecreatetruecolor($ratio, round(($ratio/$tableau[0])*$tableau[1]));
imagecopyresampled($im, $src, 0, 0, 0, 0, $ratio, round($tableau[1]*($ratio/$tableau[0])), $tableau[0], $tableau[1]);
}
header ("Content-type: image/jpeg");
imagejpeg ($im);
}
elseif ($tableau[2] == 3) { // PNG
$src = imagecreatefrompng($dir.'/'.$image);
if ($tableau[0] > $tableau[1]) {
$im = imagecreatetruecolor(round(($ratio/$tableau[1])*$tableau[0]), $ratio);
imagecopyresampled($im, $src, 0, 0, 0, 0, round(($ratio/$tableau[1])*$tableau[0]), $ratio, $tableau[0], $tableau[1]);
}
else {
$im = imagecreatetruecolor($ratio, round(($ratio/$tableau[0])*$tableau[1]));
imagecopyresampled($im, $src, 0, 0, 0, 0, $ratio, round($tableau[1]*($ratio/$tableau[0])), $tableau[0], $tableau[1]);
}
header ("Content-type: image/png");
imagepng ($im);
}
}
}
?>
任何想法?
事实上,它只是ftp上传到网站外部,所以,不,文件名不被检查。但在这里,我仔细检查了名字,没有任何问题。无论如何,正如我所说的,每个缩略图有时会显示,并且所有工作都是在缩略图直接在浏览器中调用的。 – Steph 2012-02-04 13:21:06
好的。它可能是一个路径错误?在子文件夹中是mini.php。因为如果是这种情况,并且您从图像中调用它,那么也许您的'$ dir。'/''不再适用了......如果不是,我很抱歉我没有找到任何解决方案... – 2012-02-06 15:53:35