first commit
This commit is contained in:
119
mois.php
Normal file
119
mois.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
$base = 'db_photo.sqlite3';
|
||||
|
||||
//Get a list of file paths using the glob function.
|
||||
$fileList = glob('photos/img/*');
|
||||
|
||||
// Connexion
|
||||
$conn = new PDO("sqlite:db_photo.sqlite3");
|
||||
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$query = "CREATE TABLE IF NOT EXISTS photos (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
filename TEXT,
|
||||
date TEXT,
|
||||
lens TEXT,
|
||||
width INTEGER,
|
||||
height INTEGER,
|
||||
UNIQUE(filename)
|
||||
)";
|
||||
$conn->exec($query);
|
||||
/*
|
||||
lens TEXT,
|
||||
width INTEGER,
|
||||
height INTEGER,
|
||||
*/
|
||||
|
||||
function _pr($d) {
|
||||
echo "<div style='border: 1px solid#ccc; padding: 10px;'>";
|
||||
echo '<strong>' . debug_backtrace()[0]['file'] . ' ' . debug_backtrace()[0]['line'] . '</strong>';
|
||||
echo "</div>";
|
||||
echo '<pre>';
|
||||
if(is_array($d)) {
|
||||
print_r($d);
|
||||
} else if(is_object($d)) {
|
||||
var_dump($d);
|
||||
}
|
||||
echo '</pre>';
|
||||
}
|
||||
|
||||
#_pr($items);
|
||||
|
||||
// Ajout de données dans la table
|
||||
foreach($fileList as $file){
|
||||
$exif = exif_read_data($file,'EXIF' ,0 );
|
||||
#_pr($exif);
|
||||
$ht = $exif['COMPUTED']['html'];
|
||||
$wi = $exif['COMPUTED']['Width'];
|
||||
$he = $exif['COMPUTED']['Height'];
|
||||
$ap = $exif['COMPUTED']['ApertureFNumber'];
|
||||
# YYYY-MM-DD HH:MM:SS.SSS - 2019:10:01 14:03:12
|
||||
$da = $exif['DateTimeOriginal'];
|
||||
$mod = $exif['Model'];
|
||||
$ex = $exif['ExposureTime'];
|
||||
$iso = $exif['ISOSpeedRatings'];
|
||||
$obj = isset($exif['UndefinedTag:0xA434']) ? $exif['UndefinedTag:0xA434'] : "";
|
||||
|
||||
#echo $file . " - " . $ww . " - " . $hh . " - " . $dd . "<br>";
|
||||
|
||||
$photos[] = array(
|
||||
'filename' => $file,
|
||||
'date' => $da,
|
||||
'lens' => $obj,
|
||||
'width' => $wi,
|
||||
'height' => $he
|
||||
);
|
||||
}
|
||||
|
||||
#_pr($photos);
|
||||
|
||||
try {
|
||||
$conn2 = new PDO('sqlite:db_photo.sqlite3');
|
||||
$query2 = "INSERT OR IGNORE INTO photos (filename, date, lens, width, height) VALUES (:filename, :date, :lens, :width, :height)";
|
||||
|
||||
$stmt = $conn2->prepare($query2);
|
||||
$stmt->bindParam(':filename', $file);
|
||||
$stmt->bindParam(':date', $da);
|
||||
$stmt->bindParam(':lens', $obj);
|
||||
$stmt->bindParam(':width', $wi);
|
||||
$stmt->bindParam(':height', $he);
|
||||
|
||||
|
||||
foreach ($photos as $item) {
|
||||
_pr($item);
|
||||
$file = $item['filename'];
|
||||
$da = $item['date'];
|
||||
$obj = $item['lens'];
|
||||
$wi = $item['width'];
|
||||
$he = $item['height'];
|
||||
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
#header('location: index.php');
|
||||
|
||||
$conn2 = null;
|
||||
}
|
||||
catch(PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
//
|
||||
/**/
|
||||
try {
|
||||
$conn3 = new PDO('sqlite:db_photo.sqlite3');
|
||||
$query3 = "SELECT filename, date, lens, width, height FROM photos WHERE id >= ? AND id <= ? ORDER BY date DESC";
|
||||
|
||||
$stmt = $conn3->prepare($query3);
|
||||
# id 1 -> 3
|
||||
$stmt->execute(array(1, 3));
|
||||
|
||||
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
_pr($result);
|
||||
|
||||
$conn3 = null;
|
||||
}
|
||||
catch(PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user