2012-05-29 47 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>'; 
} 
相關問題