Scam
Invité n'ayant pas de compte PHPfrance
14 sept. 2005, 15:18
Salut, j'ai un petit soucis avce un script, et je n'arrive pas a touver l'erreur
$nb_rand = mt_rand(0, 10); //nombre aléatoire entre 0 et 10
$fichiers = array();
//FIXER $dir
//Lister les fichiers du répertoire $dir
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if (filetype($dir . $file) === 'file') {
$fichiers[] = $dir . $file;
}
}
closedir($dh);
} else {
die("Impossible d'ouvrir le dossier");
}
$fichiers = array_rand($fichiers, $nb_rand); //garder au hazard $nb_rand fichiers du tableau
$fichier_cache = "truc.php";
$f = fopen($fichier_cache,"w");
if ($f) {
//Lire et concaténer le contenu des fichiers retenus
foreach($fichiers as $key=>$file) {
fwrite($f, file_get_contents($file) );
}
fclose($f);
} else {
die("Impossible d'ouvrir le fichier de cache");
}
voici quelques messages d'erreur
Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in /index.php on line 22
Warning: Invalid argument supplied for foreach() in /index.php on line 27
ou encore (apres rafraichissement)
Warning: file_get_contents(2): failed to open stream: No such file or directory in /index.php on line 28
Warning: file_get_contents(6): failed to open stream: No such file or directory in /index.php on line 28
Warning: file_get_contents(8): failed to open stream: No such file or directory in /index.php on line 28
il me crée bien un fichier $fichier_cache = "truc.php"; mais il fait 0 octé