2013-02-18 88 views
0

我正在製作帶有圖像文件夾和子文件夾的照片庫。我想不必在每個文件夾中放置一個HTML文件。如何才能做到這一點?這是我的PHP:在每個目錄文件夾中自動運行PHP和HTML

<?php 

$directory = "thumbs/"; 
$files = glob($directory."*"); 
$photoCount = 0; 

buildStage(); 

function buildStage() { 
    global $directory, $files; 

    foreach($files as $file) { 
     if(is_dir($file)) showFolder($file); 
     else showPhotos($directory);  
    } 
} 

function showPhotos($imagePath) { 
    global $photoCount; 
    $imageFile = glob($imagePath."/*.*"); 
    echo '<img src="'.$imageFile[$photoCount].'" id="thumbPic" 
      onmouseover="imageOver(this)" 
      onmouseout="imageOut(this)" 
      />'."\n"; 
    $photoCount++; 
} 

function showFolder($imagePath) { 
    $imageFile = glob($imagePath."/*.*"); 
    echo '<a href="' .$imagePath. '<img src="'.$imageFile[1].'" id="folder" 
      onmouseover="imageOver(this)" 
      onmouseout="imageOut(this)" 
      onmousedown="imageDown(this)" 
      />'."\n"; 
} 

?> 

這裏是我的HTML:

<body> 

<div id="container"> 
<?php include 'jellybox.php'; ?> 
</div> 

</body> 

感謝所有幫助你可以給。

+0

爲什麼你需要在每個文件夾中的HTML文件? – Pitchinnate 2013-02-18 15:15:39

+0

我只是在尋找一種方式來做照片庫目錄。這是迄今爲止我所在的地方。當您單擊「PHP圖像」中的圖像時,它會打開文件夾,但沒有索引文件,因此會出現錯誤。有什麼想法嗎? – dougburnett 2013-02-18 21:53:20

回答

0

你可以使用htaccess的每一個文件映射到你的PHP代碼:

Options +FollowSymLinks 

RewriteEngine On 
RewriteBase /dependsOnyourPathes/ 
RewriteRule ^[images|thumb]/(.+).jpg$ script.php?file=$1.pdf [L,NC,QSA] 

這顯示在瀏覽器欄的老圖片的網址,但在內部調用你的PHP腳本。我不完全確定你正在嘗試什麼。您也可以重寫 現有文件夾並將其發送到您的腳本。對於更確切的答案,我們需要更多關於服務器上的文件位置的更多信息。

+0

這似乎可以工作。這是我想要在上下文中做的。 http://dougburnett.com/gsap-test/。 – dougburnett 2013-02-18 21:50:24

相關問題