Je veux rechercher dans les fichiers et créer des images à partir de fichiers jpg. Il y a le code:rechercher tous les fichiers et répertoires pour créer des vignettes dans php
$dir2 = opendir($direction2);
$dir = opendir($direction);
function create_fcat($direction, $width, $direction2, $dir) {
while(false !== ($fn = readdir($dir))) {
$n_dir = $direction.'/'.$fn;
if (is_dir($n_dir) && $fn != '.' && $fn != '..') {
if ($handle = opendir($n_dir)) {
create_fcat($fn, $width, $direction2, $handle);
}
} elseif ($fn != '.' && $fn != '..') {
$ext = strtolower(substr($fn,strlen($fn)-3));
if ($ext == 'jpg') {
if ($img = imagecreatefromjpeg($direction.'/'.$fn)) {
$width_original = imagesx($img);
$height_original = imagesy($img);
if ($width_original > $height_original) {
$new_width = $width;
$new_height = floor($height_original * ($width/$width_original));
} else {
$new_height = $width;
$new_width = floor($width_original * ($width/$height_original));
}
$tmp_img = imagecreatetruecolor($new_width, $new_height);
imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width_original, $height_original);
imagejpeg($tmp_img, $direction2.'/large/'.$fn);
} else {
echo '<p>The file cannot be loaded.</p>';
}
}
}
}
closedir($dir);
}
Le problème est le suivant: lorsque, par exemple, nous avons ces fichiers:
- PRINCIPAUX
- image1.jpg
- FOLDER1
- image2.jpg
- DOSSIER 1. 1
- image3.jpg
fichiers image1.jpg et image2.jpg sont chargés, mais image3.jpg n'est pas - il semble que FOLDER 1.1 est traité comme fichier. Comment puis-je le réparer?