2013-08-07 2 views
0

이 스크립트는 디렉토리를보고 모든 gif, jpg, jpeg 및 png 파일을 식별하고 본문 섹션에 표시합니다. 디렉토리에는 이미지가 있고 그 다음 끝에 "_t"가 추가 된 각 이미지의 복사본이 있습니다. 표시된 "_t"이미지는 라이트 박스에 표시되는 풀 사이즈 이미지에 대한 링크입니다. 본질적으로 엄지 손톱 시스템입니다.Div/테이블 행에 PHP 이미지 및 이름 반복

아래 이미지/디렉토리가 제거 된 파일 이름은 $ filename으로 저장됩니다.

자동 생성 된 미리보기 이미지로 내용을 표시하는 해킹으로 작성된 Lightbox2의 표시 스크립트에서 채택되었습니다. 내 질문에 대한 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 "<table border=1><td><a href='".$image_dir.$image_file."' title='$filename' rel='".$rel."' data-lightbox=".$filename."> 
<img src='".$image_dir.$filename."_t.".$filetype."' alt='".$filename."' width='100' height='80' title=''/ ><br> 
$filename</td> 
</a> 

" ."\n "; 
      } 
     } 
    } 
    ?> 

단부 단지 </A하기 전에 : 여기

내가 지금까지 가지고있는 코드입니다. 그러나이 스크립트는 이미지 당 줄 바꿈을 수행 할 때와 같이 이미지의 직선 컬럼을 만들고 (각각 파일 이름 바로 아래에 파일 이름이 만들어 짐) 만듭니다.

[] [] [] [] [] []

: 내가 원하는 무엇

는 다음과 같은 서로에 대한 표시 (등 또는 div의) 테이블 셀을 가지고있다. 5 개의 미리보기 이미지를 통해 새로운 행을 시작하십시오.

나는 내 일들이 foreach는 동안, 각 이미지 아래에 표시되는 $ 파일 이름에 걸쳐 행 당 반향되는 5 개 이미지 결과 다음 그 아래에 새 줄을 시작한다는 에코 포맷 할 수 있습니다 방법 ?

편집 : 코드는 원래 http://www.fatbellyman.com/webstuff/lightbox_gallery/index.php

답변

0

여기에 내가 이것을 달성하기 위해 무슨 짓을했는지 :

<?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'; 
     $piccounter = 0; /* this is how we monitor the length of the rows */ 
      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){ 
/*Variable $piccounter is the number of thumbnails across in the page per row*/ 
    if ($piccounter >= 6){ echo "<tr />"; $piccounter=0; } /*Every 6, drop in a </tr> and reset the variable for the new row */ 
echo "<td><a href='".$image_dir.$image_file."' title='$filename' rel='".$rel."' data-lightbox=".$filename."> 
<img src='".$image_dir.$filename."_t.".$filetype."' alt='".$filename."' width='100' height='80' title=''/ ><br> 
$filename<br/> 
</a></td>"; /*$filename is both the image name AND the caption in expanded lightbox*/ 
$piccounter++; /*After each image, add 1 to the $piccount counter to keep track of the length of the rows*/ 


       } 
     } 
    } 

    ?> 

변수 $ piccounter 인쇄했다 얼마나 많은 축소판을 추적하기 위해 만들어졌습니다. 6을 치면 테이블 행이 삽입됩니다. 그렇지 않으면 foreach 프로세스가 TD를 만듭니다.

페이지 자체에이 스크립트 호출을 사용하여 테이블 열기/닫기를 추가합니다.

0

내가 계산 특정 행에 (여기에 대한 테스트) 루프에서 테이블을 생성하기 위해이 따라 뭔가를 사용에서 :

<?php 
$table_rows=5; 

$table = "<table border=1><tbody>"; 
$i = 1; 

for ($j = 0; $j < 13; $j++){ 

    if($i == 1) { 
     $table .= "<tr>"; 
    } 

    $table .= "<td>".$j." ".$i."</td>"; 

    $i = (($i+1)%$table_rows); 

    if($i == 1) { 
     $table .= "</tr>"; 
    } 
} 

if($i != 1){ 
    $table .= "</tr>"; 
} 

$table .= "</tbody></table>"; 

echo $table; 
?> 

을 나는이 것을 확신합니다 가장 쉬운 방법은 아니며 코드는 끔찍한 것처럼 보이지만 대개는 저에게 효과적입니다.

+0

그리고 사이에 내 에코 기능을 감싸는 것 "$ 테이블 =." ";. } $ 테이블 =" ".. $ j에"을 "$ i." "; -? – Arman

+0

과 사이의 텍스트를 반향 텍스트로 바꾸십시오. – mnme

+0

이 작업은 작동하지 않습니다.이 작업은 13 개의 작은 공백 테이블로 가득 찬 페이지의 중간에 한 개의 이미지 크기 표를 삽입하는 것입니다. – Arman