match('/heic|HEIC|jpg|jpeg|JPG|JPEG|webp|WEBP$/'); //echo '

' . count($dir) . gettext(' images found in folder') . ' photos/img/ ...

'; //_pr($dir); /* foreach($dir as $file){ //$file->getFilename() //$file->getpathName() $file = $file->getpathName(); $x = in_bdd($file); if ($x == false) { //false } } */ $originals = array_map('basename', glob('photos/img/*.{jpg,jpeg,JPG,JPEG,heic,HEIC,webp,WEBP}', GLOB_BRACE)); $thumbs = array_map('basename', glob('photos/thumb/*.{jpg,jpeg,JPG,JPEG,heic,HEIC,webp,WEBP}', GLOB_BRACE)); $missing_thumbs = array_diff($originals, $thumbs); $a = count($missing_thumbs); echo '

' . gettext('Missing thumbs: ') . $a . '

'; if ($a > 0) { echo '

' . gettext('Create missing thumbs...') . '

'; foreach($missing_thumbs as $img){ $file = $img_path . $img; create_thumb($th_w, $th_h, $file); echo gettext('Thumb for ') . $img . gettext(' was successfully created!') . '
'; } } $missing_originals = array_diff($thumbs, $originals); $b = count($missing_originals); echo '

' . gettext('Extra thumbs: ') . $b . '

'; if ($b > 0) { echo '

' . gettext('Delete extra thumbs...') . '

'; foreach($missing_originals as $thumb){ $file = $thumb_path . $thumb; if (unlink($file)) { echo $thumb . gettext(' was deleted successfully!') . '
'; } else { echo gettext('There was a error deleting the file ') . $thumb; } } } _pr($missing_thumbs); _pr($missing_originals); echo '

' . gettext('Compare folder img and daatabase...') . '

'; try { $conn = new PDO("sqlite:db_photo.sqlite3"); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $query = "SELECT filename FROM photos"; $stmt = $conn->prepare($query); $stmt->execute();// (1,3...) 1=1ere valeur 3=valeur $result = $stmt->fetchAll(PDO::FETCH_CLASS); $rowcount = count($result); //$conn = null; } catch(PDOException $e) { echo $e->getMessage(); } //_pr($result); $bdd = array(); foreach($result as $file) { //$img = $file->filename; $bdd[] = $file->filename; } $base = array_map('basename', $bdd); $missing_originals = array_diff($base, $originals); $c = count($missing_originals); echo '

' . gettext('Extra images in database: ') . $c . '

'; if ($c > 0) { echo '

' . gettext('Delete extra images in database...') . '

'; //foreach($missing_originals as $img){ foreach($missing_originals as $key => $img){ echo $key; $query2 = "DELETE FROM photos WHERE id=:id"; $stmt=$conn->prepare($query2); $stmt->bindParam(':id',$key,PDO::PARAM_INT, 5); if($stmt->execute()){ echo "Successfully deleted record "; } else { print_r($sql->errorInfo()); } } } //_pr($bdd); //_pr($base); _pr($missing_originals); /* foreach($fileList as $filename){ echo $filename; } */ //_pr($fileList); ?>

© 2013- sur-le-sentier.fr