2013-02-18 4 views
3

PHP 라이트 박스 (this-http://www.fatbellyman.com/webstuff/lightbox_gallery/index.php)를 사용하여 축소 이미지와 이미지를 자동으로 표시합니다. 제목과 이미지 설명을 별도의 목록 (텍스트 파일?)에서 가져온 더 큰 라이트 박스 이미지에 표시하고 싶습니다. 최선의 데이터베이스를 사용하지 않고이 작업을 수행 할 수 있다면 가능합니다.라이트 박스 이미지의 제목을 얻는 방법

이 내 갤러리 페이지에 있습니다 :

<?php include 'lightbox_display_function.php'; ?> 
<?php lightbox_display('apparel/soiled/icarus/', 'lightbox[icarus]'); ?> 

그리고 이것은 lightbox_display_function.php입니다 :

<?php function lightbox_display($dir_to_search, $rel){ 
     $image_dir = $dir_to_search; 
     $dir_to_search = scandir($dir_to_search); 
     $image_exts = array('gif', 'jpg', 'jpeg', 'png'); 
     $excluded_filename = '_t'; 
      foreach ($dir_to_search as $image_file){ 
      $dot = strrpos($image_file, '.'); 
      $filename = substr($image_file, 0, $dot); 
      $filetype = substr($image_file, $dot+1); 
      $thumbnail_file = strrpos($filename, $excluded_filename); 
       if ((!$thumbnail_file) and array_search($filetype, $image_exts) !== false){ 
echo "<a href='".$image_dir.$image_file."' rel='".$rel."'> 
<img src='".$image_dir.$filename."_t.".$filetype."' alt='".$filename."' width='70' height='70' title='$filename'/> 
</a>"."\n"; 
       } 
      } 
    } 

답변

0

당신이 순간에 구조 페이지를 얼마나 몇 가지 예제 코드가 있습니까, 내 머리 꼭대기에서 일종의 연관 배열로 하드 코딩 할 수는 없을까요?

제목이 필요한 파일과 페어링 할 수 있도록 이미지 파일 이름을 키로 설정 하시겠습니까?

당신이 지금까지 가지고있는 것을 게시하면 우리는 한 번 봐도 좋고 제안을 할 수 있습니다.

- 업데이트 -

하드 코어 당신이 그것을 호출과의 요소가 기능에서 해당 이미지와 함께 짝을 할 수 있도록 매개 변수로 배열을 포함하기 전에 페이지의 배열입니다.

<?php include 'lightbox_display_function.php'; ?> 
<?php 
$titleArray=array(); 
$titleArray['RedCar.jpg']="Picture of red car"; 
$titleArray['BlueCar.jpg']="Picture of blue car"; 
$titleArray['GreenCar.jpg']="Picture of green car"; 
lightbox_display('apparel/soiled/icarus/', 'lightbox[icarus]',$titleArray); 
?> 

그래서 이제 함수에서 우리는 내가 그것을 테스트하지 않았습니다

<?php function lightbox_display($dir_to_search, $rel,$titleArray){ 
      $image_dir = $dir_to_search; 
      $dir_to_search = scandir($dir_to_search); 
      $image_exts = array('gif', 'jpg', 'jpeg', 'png'); 
      $excluded_filename = '_t'; 
       foreach ($dir_to_search as $image_file){ 
       $dot = strrpos($image_file, '.'); 
       $filename = substr($image_file, 0, $dot); 
       $filetype = substr($image_file, $dot+1); 
       $thumbnail_file = strrpos($filename, $excluded_filename); 

       $title=""; 
       if (array_key_exists($filename, $titleArray)) { //check if the filename matches a key in the array 
        $title = $titleArray[$filename]; //match, so set $title to equal the title set for that image name in the array 
       } 

       if ((!$thumbnail_file) and array_search($filetype, $image_exts) !== false){ 
        //At this point $title can be included in the echo or used in some fashion, put is paired up with the appropriate image. 
        echo "<a href='".$image_dir.$image_file."' rel='".$rel."'> 
        <img src='".$image_dir.$filename."_t.".$filetype."' alt='".$filename."' width='70' height='70' title='$filename'/> 
        </a>"."\n"; 
        } 
       } 
     } 

와 함께 작동하도록 정보를 가지고 있지만 그것은 당신에게 함께 일할 것을, 이론 아무것도 경우를 제공해야합니다.

+0

고마워요! 위의 질문에 코드를 추가했습니다. 당신이 묘사하고있는 것은 내가하려는 일처럼 들리지만, 아직 일어날만큼 충분한 지식이 없습니다! – apol

+0

도움 주셔서 감사합니다! 나는 아직도 그것을 작동 시키려고 노력하고 있지만, 나는 그 방향에 정말로 감사한다. – apol