我的网站上有一张图片:
www.blah.com/gallery/gallery/2244.jpg
如果我直接输入此网址,我会看到图片。
现在,我有一个小图库,我想要显示图像(和其他图像),但是,使用以下代码它根本不显示:
$files = glob("/home/mysite/public_html/gallery/gallery/*.*");
for ($i=1; $i<count($files); $i++)
{
$num = $files[$i];
echo '<a class="fancybox-effects-a" rel="gallery" href="'.$num.'">';
echo '<img src="'.$num.'" class="gallery_img" alt=""></a>';
}
图像上传时没有错误(使用http://www.verot.net/php_class_upload.htm):
if(isset($_FILES['image'])){
include('/home/mysite/php/lib/img_upload/class.upload.php');
// retrieve eventual CLI parameters
$cli = (isset($argc) && $argc > 1);
if ($cli) {
if (isset($argv[1])) $_GET['file'] = $argv[1];
if (isset($argv[2])) $_GET['dir'] = $argv[2];
if (isset($argv[3])) $_GET['pics'] = $argv[3];
}
// set variables
$dir_dest = (isset($_GET['dir']) ? $_GET['dir'] : 'test');
$dir_pics = (isset($_GET['pics']) ? $_GET['pics'] : $dir_dest);
if (!$cli) {
// ---------- IMAGE UPLOAD ----------
$handle = new Upload($_FILES['image']);
if ($handle->uploaded) {
$handle->image_resize = true;
$handle->image_ratio_x = true;
$handle->image_y = 500;
$handle->Process('/home/mysite/public_html/gallery/gallery/');
// we check if everything went OK
if ($handle->processed) {
// everything was fine !
$success .= 'Image uploaded to the gallery successfully!';
} else {
// one error occured
$error .= '<li>file not uploaded to the wanted location';
$error .= '<li>Error: ' . $handle->error . '';
}
// we now process the image a second time, with some other settings
/******************************/
// produce thumbnails
/*****************************/
$handle->image_resize = true;
$handle->image_ratio_x = true;
$handle->image_y = 120;
$handle->image_reflection_height = 50;
$handle->image_reflection_opacity = 90;
$handle->image_convert = 'png';
$handle->Process('/home/mysite/public_html/gallery/gallery/thumbs/');
// we check if everything went OK
if ($handle->processed) {
// everything was fine !
$success .= '<p>Thumbnail created successfully, see below...';
$success .= '<p><img src="/gallery/gallery/thumbs/' . $handle->file_dst_name . '" />';
} else {
// one error occured
$error .= 'file not uploaded to the wanted location';
$error .= ' Error: ' . $handle->error . '';
}
/******************************/
// END use this if you want to produce thumbnails
/*****************************/
// we delete the temporary files
$handle-> Clean();
} else {
// if we're here, the upload file failed for some reasons
// i.e. the server didn't receive the file
$error .= '<li>file not uploaded on the server';
$error .= '<li>Error: ' . $handle->error . '';
}
}
}
我根本无法理解这一点!
答案 0 :(得分:2)
看起来您将src
设置为图像的绝对路径。试试这个:
foreach (glob('/home/mysite/public_html/gallery/gallery/*.jpg') as $file) {
$file = '/gallery/gallery/'.basename($file);
echo '<a class="fancybox-effects-a" rel="gallery" href="'.$file.'">';
echo '<img src="'.$file.'" class="gallery_img" alt=""></a>';
}