Nom de l'image | Titre de l'image | Commentaire sur l'image
Et le code php commencé comme suit :
//-----------Des titres et commentaires------------
if (file_exists($currentdir ."/infos.txt"))
{
$fichier = fopen($currentdir ."/infos.txt", "rb");
while (!feof($fichier) )
{
// Chaque ligne est prise en compte
$line_of_text = fgets($fichier);
$parts = explode('/n', $line_of_text);
foreach($parts as $img_infos)
{
list($img_filename, $img_titre, $img_comment) = explode('|', $img_infos);
}
}
fclose($file_handle);
}
//-----------------------
Ainsi j'ai les infos du txt. Comment préciser dans ce code que l'information donnée correspond à l'image citée "$img_filename"?
on fait on mieux de nos compétence et des disponibilitésJe m’étonne de l'absence totale de réponse.
<?php
$fileInfo = $currentdir . "/infos.txt";
$info = array();
if (file_exists($fileInfo)) {
$files = file($fileInfo);
foreach($files as $f){
$l = str_getcsv($f,'|');
$info[$l[0]] = array_slice($l,1,count($l));
}
}
?>
a partir de la tu as un tableau qui contient les infos des images. Tu les récupère simplement avec $info['nom du fichier'] <?php
//-------------------------------------------
// Les légendes du fichier texte
$infos = $path ."/infos.txt";
if (file_exists($infos)) {
$fichier_txt = fopen($infos, "r");
while (!feof($fichier_txt) )
{
$ligne_txt = fgets($fichier_txt);
$parts = explode('/n', $ligne_txt);
foreach($parts as $img_infos)
{
list($img_nom, $img_legende) = explode('|', $img_infos);
$img_legendes[$img_nom] = $img_legende;
}
}}
fclose($fichier_txt);
//test
echo $img_legendes['1.jpg'];
//-------------------------------------------
?>
Dans l'ensemble du script les images sont traitées via les fonctions opendir et readdir et j'ai opté pour un fichier texte image.jpg|Légende de l'image
<?php
$dossier = 'le dossier/';
$lesimages = file($dossier);
foreach ($lesimages as $image){
echo '<img src="'.$dossier.$image.'" /><br />';
echo '<p class="legend">'.$info[$image].'</p>';
}
?>
Par exemple1.jpg|Un lion
2.jpg|Un dauphin
3.jpg|Un poney
Ce fichier texte est placé dans le dossier "animaux" du dossier "galerie"
$display = $path2 . "/gallery/" . $open . "/" . $ff[$key]; $vals = $ff[$key];
$sizes = @getimagesize($display);
if($key == $n) { break; }
if($key < $num) { continue; }
// resize images
if ($sizes[0] >= $sizes[1] && $sizes[0] > $thumbs_WH) {
$resize = $sizes[0]/$thumbs_WH;
$width = round($sizes[0]/$resize);
$height = round($sizes[1]/$resize);
$margin = round(($thumbs_WH - $height)/2);
$img = '<div class="gall_thumb" style="height:' . $thumbs_WH . 'px; width:' . $thumbs_WH . 'px;">' . '<a style="width:' . $thumbs_WH . 'px; height:' . $thumbs_WH . "px; display:block;\" href=\"javascript:void(0)\" onClick=\"loadurl('$path2/scripts/onepage.php?content=$open&num=$num&slika=$key'); return true \" >" . '<img style="margin-top:' . $margin . 'px;" src="' . $display . '" width="' . $width . '" height="' . $height . '" border="0" alt="" title="" /></a></div>' ;
$resize2 = $sizes[0]/$image_WH;
$width2 = round($sizes[0]/$resize2);
$height2 = round($sizes[1]/$resize2);
$img2 = '<img src="' . $display . '" width="' . $width2 . '" height="' . $height2 . '" border="0" alt="" title="" alt="" />';
$slike[$key] = $img2;
} elseif($sizes[0] < $sizes[1] && $sizes[1] > $thumbs_WH) {
$resize = $sizes[1]/$thumbs_WH;
$height = round($sizes[1]/$resize);
$width = round($sizes[0]/$resize);
$margin = round(($thumbs_WH - $height)/2);
$img = '<div class="gall_thumb" style="height:' . $thumbs_WH . 'px; width:' . $thumbs_WH . 'px;">' . '<a style="width:' . $thumbs_WH . 'px; height:' . $thumbs_WH . "px; display:block;\" href=\"javascript:void(0)\" onClick=\"loadurl('$path2/scripts/onepage.php?content=$open&num=$num&slika=$key'); return true \" >" . '<img style="margin-top:' . $margin . 'px;" src="' . $display . '" width="' . $width . '" height="' . $height . '" border="0" alt="" title="" /></a></div>';
$resize2 = $sizes[1]/$image_WH;
$width2 = round($sizes[0]/$resize2);
$height2 = round($sizes[1]/$resize2);
$img2 = '<img src="' . $display . '" width="' . $width2 . '" height="' . $height2 . '" border="0" alt="" title="" alt="" />';
$slike[$key] = $img2;
} else {
$width = $sizes[0];
$height = $sizes[1];
$margin = round(($thumbs_WH - $height)/2);
$img = '<div class="gall_thumb" style="height:' . $thumbs_WH . 'px; width:' . $thumbs_WH . 'px;">' . '<a style="width:' . $thumbs_WH . 'px; height:' . $thumbs_WH . "px; display:block;\" href=\"javascript:void(0)\" onClick=\"loadurl('$path2/scripts/onepage.php?content=$open&num=$num&slika=$key'); return true \" >" . '<img style="margin-top:' . $margin . 'px;" src="' . $display . '" width="' . $width . '" height="' . $height . '" border="0" alt="" title="" /></a></div>';
$width2 = $sizes[0];
$height2 = $sizes[1];
$img2 = '<img src="' . $display . '" width="' . $width2 . '" height="' . $height2 . '" border="0" alt="" title="" />';
$slike[$key] = $img2;
}
$thumbs = @$thumbs . $img;
} <?php
error_reporting(E_ALL);
ini_set("display_errors", "1");
$open = @$_GET['content'];
$num = @$_GET['num'];
$slik = @$_GET['slika'];
$path = $_SERVER['DOCUMENT_ROOT'] . "site/onepage/";
$path2 = "http://" . $_SERVER['SERVER_NAME'] . "/site/onepage";
$thumbs_break = '<div id="thumbs_break"> </div>';
include_once($path . "scripts/onepage_custom.php");
$main_dir = opendir($path . "gallery");
while (false !== ($folders = readdir($main_dir))) {
if($folders == "." || $folders == ".." ) {
continue;
} else {
$dirs[] = $folders;
}
}
sort($dirs);
if(count($dirs) != count($all_dirs) || $all_dirs[0] == "") {
$chosen = $dirs;
} else {
$chosen = $all_dirs;
}
if(empty($open) || array_search($open, $chosen) === FALSE) {
$dir = $path . "gallery/" . $chosen[0];
$open = $chosen[0];
} else {
$dir = $path . "gallery/" . $open;
}
// Affiche le nom des autres galleries à partir du fichier texte
foreach($chosen as $val) {
if(strpos($dir, $val) === FALSE) {
$dir_nasl = file($path . "gallery/" . $val . "/title.txt");
$dirs_nasl = @$dirs_nasl . "<a href=\"javascript:void(0)\" onClick=\"loadurl('$path2/scripts/onepage.php?content=$val'); return true \" >$dir_nasl[0]</a>";
}
}
$count_dirs = count($chosen);
if($count_dirs > 1){
$other_dirs = '<div id="gall_other">Les autres galeries:' . $dirs_nasl . '</div>';
} else {
$other_dirs = '<div id="gall_other"> </div>';
}
$openDir = opendir($dir);
while (false !== ($fileNames = readdir($openDir)))
{
if(strpos($fileNames, "txt") !== FALSE && strpos($fileNames, "title") !== FALSE ) {
$gall_nasl = file($dir . "/" . $fileNames);
$gall_naslov = '<div id="gall_title">' . $gall_nasl[0] . '</div>';
}
if($fileNames == "." || $fileNames == ".." || strpos($fileNames, "txt") !== FALSE) {
continue;
} else {
$ff[] = $fileNames;
}
}
$count_ff = count($ff);
if($num == "") {
$num = 0;
}
$n=$num+$max_thumbs;
$p=$num-$max_thumbs;
if($p < 0 ) {
$prev = '<div id="gall_prev" style="height:' . $thumbs_WH . 'px; background:transparent;"> </div>';
} else {
$prev = '<div id="gall_prev" style="height:' . $thumbs_WH . 'px;">' . '<a style="height:' . $thumbs_WH . 'px;"' . "href=\"javascript:void(0)\" onClick=\"loadurl('$path2/scripts/onepage.php?content=$open&num=$p'); return true \" > </a>" . '</div>';
}
if($n > ($count_ff-1)) {
$next = '<div id="gall_next" style="height:' . $thumbs_WH . 'px; background:transparent;"> </div>';
} else {
$next = '<div id="gall_next" style="height:' . $thumbs_WH . 'px;">' . '<a style="height:' . $thumbs_WH . 'px;"' . " href=\"javascript:void(0)\" onClick=\"loadurl('$path2/scripts/onepage.php?content=$open&num=$n'); return true \" > </a>" . '</div>';
}
foreach($ff as $key => $value) {
$display = $path2 . "/gallery/" . $open . "/" . $ff[$key];
$vals = $ff[$key];
$sizes = @getimagesize($display);
if($key == $n) { break; }
if($key < $num) { continue; }
// resize images
if ($sizes[0] >= $sizes[1] && $sizes[0] > $thumbs_WH) {
$resize = $sizes[0]/$thumbs_WH;
$width = round($sizes[0]/$resize);
$height = round($sizes[1]/$resize);
$margin = round(($thumbs_WH - $height)/2);
$img = '<div class="gall_thumb" style="height:' . $thumbs_WH . 'px; width:' . $thumbs_WH . 'px;">' . '<a style="width:' . $thumbs_WH . 'px; height:' . $thumbs_WH . "px; display:block;\" href=\"javascript:void(0)\" onclick=\"loadurl('$path2/scripts/onepage.php?content=$open&num=$num&slika=$key;num=$num&slika=$key'); return true \" >" . '<img style="margin-top:' . $margin . 'px;" src="' . $display . '" width="' . $width . '" height="' . $height . '" border="0" alt="" title="" /></a></div>' ;
$resize2 = $sizes[0]/$image_WH;
$width2 = round($sizes[0]/$resize2);
$height2 = round($sizes[1]/$resize2);
$img2 = '<img src="' . $display . '" width="' . $width2 . '" height="' . $height2 . '" border="0" alt="" title="" alt="" />';
$slike[$key] = $img2;
} elseif($sizes[0] < $sizes[1] && $sizes[1] > $thumbs_WH) {
$resize = $sizes[1]/$thumbs_WH;
$height = round($sizes[1]/$resize);
$width = round($sizes[0]/$resize);
$margin = round(($thumbs_WH - $height)/2);
$img = '<div class="gall_thumb" style="height:' . $thumbs_WH . 'px; width:' . $thumbs_WH . 'px;">' . '<a style="width:' . $thumbs_WH . 'px; height:' . $thumbs_WH . "px; display:block;\" href=\"javascript:void(0)\" onClick=\"loadurl('$path2/scripts/onepage.php?content=$open&num=$num&slika=$key'); return true \" >" . '<img style="margin-top:' . $margin . 'px;" src="' . $display . '" width="' . $width . '" height="' . $height . '" border="0" alt="" title="" /></a></div>';
$resize2 = $sizes[1]/$image_WH;
$width2 = round($sizes[0]/$resize2);
$height2 = round($sizes[1]/$resize2);
$img2 = '<img src="' . $display . '" width="' . $width2 . '" height="' . $height2 . '" border="0" alt="" title="" alt="" />';
$slike[$key] = $img2;
} else {
$width = $sizes[0];
$height = $sizes[1];
$margin = round(($thumbs_WH - $height)/2);
$img = '<div class="gall_thumb" style="height:' . $thumbs_WH . 'px; width:' . $thumbs_WH . 'px;">' . '<a style="width:' . $thumbs_WH . 'px; height:' . $thumbs_WH . "px; display:block;\" href=\"javascript:void(0)\" onClick=\"loadurl('$path2/scripts/onepage.php?content=$open&num=$num&slika=$key'); return true \" >" . '<img style="margin-top:' . $margin . 'px;" src="' . $display . '" width="' . $width . '" height="' . $height . '" border="0" alt="" title="" /></a></div>';
$width2 = $sizes[0];
$height2 = $sizes[1];
$img2 = '<img src="' . $display . '" width="' . $width2 . '" height="' . $height2 . '" border="0" alt="" title="" />';
$slike[$key] = $img2;
}
$thumbs = @$thumbs . $img;
}
if($slik == ""){
$slika = $slike[$num];
} else {
$slika = $slike[$slik];
}
//-------------------------------------------
// Les légendes du fichier texte
$infos = $path ."/infos.txt";
if (file_exists($infos)) {
$fichier_txt = fopen($infos, "r");
while (!feof($fichier_txt) )
{
$ligne_txt = fgets($fichier_txt);
$parts = explode('/n', $ligne_txt);
foreach($parts as $img_infos)
{
list($img_nom, $img_legende) = explode('|', $img_infos);
echo $num;
$img_legendes[$img_nom] = $img_legende;
}
}}
fclose($fichier_txt);
//-------------------------------------------
echo '<div id="onepage">' . $gall_naslov . $other_dirs . '<div id="gall_thumbs">' . $prev . $thumbs . $next . $thumbs_break . '</div>' . '<div id="gall_image" style="height:' . ($image_WH+20) . 'px">' . $slika . '<br /><p>'.$img_legende.'</p></div></div>';
?>