Afficher photos
drugs52
Messages postés
187
Statut
Membre
-
Utilisateur anonyme -
Utilisateur anonyme -
Bonjour, je n'arrive pas a afficher mes images ... Pourriez vous m'aider ? voila mon code :
<html>
<head> <title>Ma galerie</title>
</head>
<body>
<?php
//déclaration d'un tableau qui contiendra le nom des fichiers
$tableau = array();
//ouverture du dossier contenant les photos
$dossier = opendir("./galerie/photos/");
while($fichier = readdir($dossier))
{
if($fichier != '.'&&$fichier !='..'&&$fichier != 'index.php')
{
//on stocke le nom des phots dans le tableau
$tableau[] = $fichier;
}
}
closedir($dossier);
//on définit le nombre de colonne sur lesquelles vont s'afficher nos photos
$nbcol= 4 ;
//on compte le nombre de photos
$nbpics= 10; //A compléter
echo"<CENTER><H1>Ma galerie de photos</H1></CENTER>";
echo"Nombre de photos= ".$nbpics."<BR/>";
//si on a au moins une photo, on les affiche toutes
if($nbpics !=0)
{
echo"<table border=1 width=100%>";
echo"<TR>";
for($i=0;$i<$nbpics;$i++)
{
//pour chaque photo, on affiche le lien vers la photo en taille réelle
echo "<TD>";
echo "<a href=\"galerie/photos/$tableau[$i]\">";
echo $tableau[$i];
echo "</a>";
echo "</TD>";
if(($i+1)%4==0)
{
echo"</tr>";
echo "<tr>";
}
}
echo "</TR>";
echo "</table>";
}
//si le tableau est vide, on affiche un petit message
else
echo"Aucune photo à afficher";
?>
</body>
</html>
<html>
<head> <title>Ma galerie</title>
</head>
<body>
<?php
//déclaration d'un tableau qui contiendra le nom des fichiers
$tableau = array();
//ouverture du dossier contenant les photos
$dossier = opendir("./galerie/photos/");
while($fichier = readdir($dossier))
{
if($fichier != '.'&&$fichier !='..'&&$fichier != 'index.php')
{
//on stocke le nom des phots dans le tableau
$tableau[] = $fichier;
}
}
closedir($dossier);
//on définit le nombre de colonne sur lesquelles vont s'afficher nos photos
$nbcol= 4 ;
//on compte le nombre de photos
$nbpics= 10; //A compléter
echo"<CENTER><H1>Ma galerie de photos</H1></CENTER>";
echo"Nombre de photos= ".$nbpics."<BR/>";
//si on a au moins une photo, on les affiche toutes
if($nbpics !=0)
{
echo"<table border=1 width=100%>";
echo"<TR>";
for($i=0;$i<$nbpics;$i++)
{
//pour chaque photo, on affiche le lien vers la photo en taille réelle
echo "<TD>";
echo "<a href=\"galerie/photos/$tableau[$i]\">";
echo $tableau[$i];
echo "</a>";
echo "</TD>";
if(($i+1)%4==0)
{
echo"</tr>";
echo "<tr>";
}
}
echo "</TR>";
echo "</table>";
}
//si le tableau est vide, on affiche un petit message
else
echo"Aucune photo à afficher";
?>
</body>
</html>
A voir également:
- Afficher photos
- Partager des photos - Guide
- Toutes mes photos - Guide
- Google photos - Télécharger - Albums photo
- Doublons photos - Guide
- Afficher taille dossier windows - Guide
2 réponses
<html><head>
<?php
extract($_GET);
$tableau=array();
if (empty($dir)) $dir="./gif";
echo "<title>Ma galerie dossier $dir </title></head><body>";
$dossier = opendir("$dir");
while($fichier = readdir($dossier))
{
if( $fichier != '.' && $fichier !='..' && $fichier != 'index.php')
{
$tableau[] = $fichier;
}
}
closedir($dossier);
$nbpics= count($tableau);
echo "<H1>Ma galerie de photos</H1> <BR>Nombre de photos= $nbpics <BR/>";
if ( $nbpics > 0)
{
echo"<table><tr>";
foreach ($tableau as $i=>$v)
{
echo "<TD><a href='$dir/$v'><img src='$dir/$v' title='$v'/></A></TD>";
if (($i+1)%4 == 0 ) echo "</tr>\n<tr>";
}
}
?>
<?php
extract($_GET);
$tableau=array();
if (empty($dir)) $dir="./gif";
echo "<title>Ma galerie dossier $dir </title></head><body>";
$dossier = opendir("$dir");
while($fichier = readdir($dossier))
{
if( $fichier != '.' && $fichier !='..' && $fichier != 'index.php')
{
$tableau[] = $fichier;
}
}
closedir($dossier);
$nbpics= count($tableau);
echo "<H1>Ma galerie de photos</H1> <BR>Nombre de photos= $nbpics <BR/>";
if ( $nbpics > 0)
{
echo"<table><tr>";
foreach ($tableau as $i=>$v)
{
echo "<TD><a href='$dir/$v'><img src='$dir/$v' title='$v'/></A></TD>";
if (($i+1)%4 == 0 ) echo "</tr>\n<tr>";
}
}
?>