我只有php的基本技能,我不得不把图片库放在一个网站上。由于这个网站将被编程知识很少的人使用,我想要一个简单的使用:上传一个带有照片的文件夹(编辑:通过FTP),相册缩略图自动显示,单击缩略图将显示完整大小的图像。
我使用了一个动态生成缩略图的脚本。如果我直接在浏览器中调用这个脚本,它似乎工作得很好。我得到了我的缩略图。但是当我在我的页面中显示一个图库时,每个图片源都是对我的脚本的调用,只有缩略图的一个随机子集被显示,其他的只显示alt文本。例如,在一个有8个页面的图库中,我第一次显示页面时可能只得到3,4和7,并且在刷新1,3,5,6,8之后:
我找不到其他拇指不能加载的错误信息,但我在php中的基本技能可能会让我失败,也许我只是不知道在哪里能找到这样的错误信息。
下面是对我的脚本的调用:
<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);
}
}
}
?>有什么想法吗?
发布于 2012-02-04 19:31:27
你说用户在你的网站上上传一个文件夹?会不会是照片名称中包含特殊字符或空格,而您在上传时不会检查?
https://stackoverflow.com/questions/9139978
复制相似问题