[Système] PB d'include : "can't redefine function .."
Bonjour à tous,
Voilà le soucis, le script ci-dessous doit lister le contenu d'un répertoire et de ses sous-répertoire.
Or comme vous le savez, dans un soucis de portabilité, je dois savoir sur quel OS je me situe d'ou l'utilisation d'un include ... mais voilà l'include ne fonctionne pas et me renvoi
Code:
Fatal error: Cannot redeclare os() (previously declared in d:\program files\easyphp1-8\www\scripts\quelSysteme.php:2) in d:\program files\easyphp1-8\www\scripts\quelSysteme.php on line 2
Voici les sources (remarquez qu'elles sont bien commentée ;) )
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
function ParcourirDossier($LienRepertoir,$extentionRecherchee="",$tableauDeFichier=false) {
// compatibilité Windows, Linux, BSD etc.
$sys = include 'quelSysteme.php';
if (ereg("Win(.*)",$sys,$occurs[])==true){
$SEPARATOR="\\";
}
else {$SEPARATOR="/";}
// récupère l'extension
$extention=str_replace(".","\.",$extentionRecherchee);
if(!$tableauDeFichier){$tableauDeFichier[0]='';}
// boucle principale
if(is_dir($LienRepertoir)){
$ClassDir= dir($LienRepertoir);
while(($nomFichier=$ClassDir->read())!=false){
// si répertoire courant ou répertoire parent, on continue
if($nomFichier=='.'||$nomFichier=='..'){
continue;
}
// s'il s'agit d'un répertoire, on fait un appel récursif
elseif(is_dir($LienRepertoir.$SEPARATOR.$nomFichier)){
$tableauDeFichier= ParcourirDossier($LienRepertoir.$SEPARATOR.$nomFichier, $extentionRecherchee,$tableauDeFichier);
}
// s'il s'agit d'un fichier contenant l'extension recherchée on le met dans la pile
elseif(ereg(".$extention$",$nomFichier)){
If($tableauDeFichier[0]==''){
$tableauDeFichier[0]=$LienRepertoir.$SEPARATOR.$nomFichier;
}
else{array_push($tableauDeFichier,$LienRepertoir.$SEPARATOR.$nomFichier);}
}
}
return $tableauDeFichier;
}
// si le répertoire spécifié n'en est pas un on retourne une erreur
else
{ echo "Erreur"; return false;}
} |
ET LE FICHIER INCLU
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
<?php
function OS($Agent=false)
{
if(!$Agent) $Agent = $_SERVER['HTTP_USER_AGENT'];
$os = null;
$OS_arr = Array('Windows NT 6.0' => 'Windows Vista',
'Windows NT 5.2' => 'Windows Server 2003',
'Windows NT 5.1' => 'Windows XP',
'Windows NT 5.0' => 'Windows 2000',
'Win 9x 4.90' => 'Windows Me.',
'Windows 98' => 'Windows 98',
'Win98' => 'Windows 98',
'Win95' => 'Windows 95',
'Mac' => 'Macintosh',
'PPC' => 'Macintosh',
'Linux' => 'Linux',
'FreeBSD' => 'FreeBSD',
'Unix' => 'Unix',
'SunOS' => 'SunOS',
'IRIX' => 'IRIS',
'BeOS' => 'BeOS',
'OS/2' => 'OS/2',
'AIX' => 'AIX');
foreach($OS_arr as $key_OS => $value_OS)
{
if(eregi($key_OS, $Agent))
{
$os = $value_OS;
}
}
if(empty($os)) return 'Inconnu';
else return $os;
}
# Exemple d'utilisation :
echo OS($_SERVER['HTTP_USER_AGENT']);
?> |
Merci d'avance les mecs ! :salut: