Exercice corrigé en php :
Solution :
exo0A.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>liens</title>
</head>
<body>
<p>
<a href="gal.php?type=C">Chien</a> -
<a href="gal.php?type=P">Poney</a> -
<a href="gal.php?type=G">Girafe</a>
</p>
</body>
</html>
----------------------------------
gal.php :
<?php
$type = isset($_GET['type']) ? $_GET['type'] : '';
if(!empty($type)){
switch($type){
case 'C':
$dossier = '../images/chien';
$title = 'Voici les chiens';
break;
case 'P':
$dossier = '../images/poney';
$title = 'Voici les poneys';
break;
case 'G':
$dossier = '../images/girafe';
$title = 'Voici les girafes';
break;
default:
$dossier = '';
$title = '';
} //fin switch
}//fin if
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $title ?></title>
</head>
<body>
<h1><?php echo $title ?></h1>
<?php
if(empty($type)){
//pas de type
echo '<p>Vous devez choisir un type de galerie</p>';
}else{
// reception d'une type
chdir($dossier);
$ouvert= opendir('.');
while($fichier = readdir($ouvert)){
if($fichier != '.' && $fichier != '..'){$files[] = $fichier;}
}//fin while
foreach($files as $value){
echo '<img src="'.$dossier.'/'.$value.'"><br />';
}
}//fin else
?>
</body>
</html>
-------
apprendre le langage php facilement et gratuitement
0 commentaires:
Enregistrer un commentaire