Dinamik görüntü açıklamaları için php içinde birden fazla dosya da dahil olmak üzere

3 Cevap

Bir php çalıştırmak galeriye resim açıklamaları uygulama üzerinde çalışıyor ve her görüntü için her metin dosyasını aramak için nasıl anlamaya görünüyor olamaz. Ben görüntü için kodu bir div yerleştirin ve daha sonra dahil aramak gerekir.

   //total number of images
   $total = 77;

   //max number of thumbnails per page
   $max = 9;

   //what image do we want to start from?
   $startcount = $_GET["start"];

   //if there is not a defined starting image, we start with the first
   if(empty($startcount))
    {
   $startcount = 0; 
  }

   //start off the loop at 1
   $loop = 1;


   //start the loop
   while($loop <= $max)
    {

   //for the picture labels
   $num = $startcount + $loop;

   if($num > $total)
    {
     $num = $num - 1;
     break;
    }

   // Add class="last" to every third list item
   if(is_int($num / 3))
    {
     $last = ' class="last"';
    }
   else
    {
     $last = "";
    }

   //the code for the image
   echo '

        <li'.$last.'><a href="images/portfolio/pic-'.$num.'.jpg" rel="milkbox[gall1]"><img src="images/portfolio/thumbs/pic-'.$num.'-thumb.jpg" width="256" height="138" alt="Thumbnail of image '.$num.'" /></a><div>'.$num.'</div></li>';

Ben kullanarak sayısına göre metin dosyalarını arayabileceğiniz görüyoruz '. $ Num.' (Ben her bir ifade ile 77 ayrı metin dosyaları var) ama nasıl dosyaları aramak için bunu söylemek istiyorsun?

3 Cevap

Her bir dosya için böyle bir şey yapmanız gerekir:

<?php 
$f=fopen($file,'r'); 
$data=''; 
while(!feof($f)) 
    $data.=fread($f,$size); 
fclose($f); 

// do whatever you want with the file content.

?>

Ben file_get_contents kullandı, ve daha kolay değiştirebilirsiniz böylece çıktılarının biraz bölünmüş:

<?php
$total = 77;
$max = 9;
$startcount = $_GET["start"];
$loop = 1;
if(empty($startcount)) $startcount = 0; 

while($loop <= $max)
{
    $num = $startcount + $loop;
    if($num > $total)
    {
        $num--;
        break;
    }
    $last = ($num % 3 == 0 ? ' class="last"' : '');

    $output = "<li $last>";
    $output .= "<a href=\"images/portfolio/pic-$num.jpg\" rel=\"milkbox[gall1]\">";
    $output .= "<img src=\"images/portfolio/thumbs/pic-$num-thumb.jpg\" width=\"256\" height=\"138\" alt=\"Thumbnail of image $num\">";
    $output .= "</a>";
    $output .= "<div>";
    $output .= file_get_contents("textfile-" . $num . ".txt"); // assuming this is where you want the phrase
    $output .= "</div>";
    $output .= "</li>";

    echo $output;
}

?>