2012-05-29 42 views
0

我已经位于我的网站上的图像:无法看到图像,但是,我知道它的存在

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

如果你改变什么'为($ i = 1; $ I <计数($文件); $ I ++)'来'为($ i = 0; $ I <数($文件); $ i ++)'。您正在跳过列表中的第一个文件。 – drew010

+0

print_r那个glob。 – HappyTimeGopher

+0

只需要注意一点:你可能希望在'glob()'中使用'* .jpg'而不是'*。*',同样使用'foreach()'比'for(;;)'简单。 – flowfree

回答

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>'; 
} 
相关问题