22-03-2022
This commit is contained in:
142
insert_bdd.php
142
insert_bdd.php
@@ -1,7 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Insert photos in Sqlite base</title>
|
||||
|
||||
<link rel="stylesheet" href="css/sls.css" />
|
||||
<link rel='stylesheet' href='css/lc_lightbox.min.css' />
|
||||
<link rel='stylesheet' href='css/open_close_fx.css' />
|
||||
<link rel='stylesheet' href='css/minimal.css' />
|
||||
|
||||
<?php include 'functions.php'; ?>
|
||||
<script src='https://code.jquery.com/jquery-3.2.1.min.js' type='text/javascript'></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<?php
|
||||
|
||||
include 'functions.php';
|
||||
|
||||
$base = 'db_photo.sqlite3';
|
||||
|
||||
// Taille des vignettes
|
||||
@@ -11,6 +29,8 @@ $th_h = 300;
|
||||
//Get a list of file paths using the glob function.
|
||||
$fileList = glob('photos/img/*');
|
||||
|
||||
echo '<h3>Creation de la base <i>' . $base . '</i> et de la table <i>photo</i> (si nécessaire)...</h3>';
|
||||
|
||||
// Création de la base et de la table photos
|
||||
$conn = new PDO("sqlite:db_photo.sqlite3");
|
||||
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
@@ -37,7 +57,8 @@ $query = "CREATE TABLE IF NOT EXISTS photos (
|
||||
UNIQUE(filename)
|
||||
)";
|
||||
$conn->exec($query);
|
||||
$conn = null;
|
||||
|
||||
echo '<h3>Lecture des fichiers images dans le dossier <i>photos/img/</i>...</h3>';
|
||||
|
||||
$i = 1;
|
||||
|
||||
@@ -85,10 +106,7 @@ foreach($fileList as $file){
|
||||
'long' => $gps['longitude'],
|
||||
'alt' => $gps['altitude']
|
||||
|
||||
);
|
||||
|
||||
//_pr($photos);
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
if ($iptc = getimagesize($file, $info)) {
|
||||
@@ -100,18 +118,18 @@ foreach($fileList as $file){
|
||||
$titre = (isset($iptc["2#105"][0])) ? $iptc["2#105"][0] : '';
|
||||
$createur = (isset($iptc["2#080"][0])) ? $iptc["2#080"][0] : '';
|
||||
$mots_cles = (isset($iptc["2#025"])) ? $iptc["2#025"] : '';
|
||||
foreach ($mots_cles as $m) {
|
||||
$mots .= $m . ",";
|
||||
}
|
||||
$mots = substr($mots, 0, -1);
|
||||
if (!empty($mots_cles)) {
|
||||
foreach ($mots_cles as $key => $val) {
|
||||
$mots .= $val . ",";
|
||||
}
|
||||
$mots = substr($mots, 0, -1);
|
||||
}
|
||||
|
||||
$photos[$i]['legende'] = $legende;
|
||||
$photos[$i]['copyright'] = $copyright;
|
||||
$photos[$i]['titre'] = $titre;
|
||||
$photos[$i]['createur'] = $createur;
|
||||
$photos[$i]['mots_cles'] = $mots;
|
||||
|
||||
//_pr($photos);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,15 +137,40 @@ foreach($fileList as $file){
|
||||
$i++;
|
||||
}
|
||||
|
||||
//_pr($photos);
|
||||
$query5 = "SELECT MAX(id) FROM photos";
|
||||
//$conn->$stmt->execute($query5);
|
||||
$stmt = $conn->prepare($query5);
|
||||
$stmt->execute();
|
||||
//$resultat = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
/*
|
||||
Array
|
||||
(
|
||||
[0] => Array
|
||||
(
|
||||
[MAX(id)] => 5
|
||||
)
|
||||
|
||||
)
|
||||
*/
|
||||
$resultat = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
/*
|
||||
Array
|
||||
(
|
||||
[MAX(id)] => 5
|
||||
)
|
||||
*/
|
||||
//_pr($resultat);
|
||||
$nb_avant = $resultat['MAX(id)'];
|
||||
|
||||
|
||||
echo '<h3>Création des vignettes dans le dossier <i>photos/thumb/</i> et insertion dans la base...</h3>';
|
||||
|
||||
// Insertion des photos dans la base
|
||||
// Création des vignettes
|
||||
try {
|
||||
$conn2 = new PDO('sqlite:db_photo.sqlite3');
|
||||
$query2 = "INSERT OR IGNORE INTO photos (filename, date, lens, exposure, iso, width, height, html, aperture, model, lat, long, alt, legende, copyright, titre, createur, keywords) VALUES (:filename, :date, :lens, :exposure, :iso, :width, :height, :html, :aperture, :model, :lat, :long, :alt, :legende, :copyright, :titre, :createur, :keywords)";
|
||||
|
||||
$stmt = $conn2->prepare($query2);
|
||||
$stmt = $conn->prepare($query2);
|
||||
$stmt->bindParam(':filename', $file);
|
||||
$stmt->bindParam(':date', $da);
|
||||
$stmt->bindParam(':lens', $obj);
|
||||
@@ -175,31 +218,72 @@ try {
|
||||
$stmt->execute();
|
||||
}
|
||||
}
|
||||
|
||||
$conn2 = null;
|
||||
}
|
||||
catch(PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
|
||||
/* Affichage depuis la bdd */
|
||||
/**/
|
||||
/* Affichage depuis la bdd des dernières images ajoutées */
|
||||
/* */
|
||||
try {
|
||||
$conn4 = new PDO('sqlite:db_photo.sqlite3');
|
||||
$query4 = "SELECT filename, date, lens, exposure, iso, width, height, html, aperture, model, lat, long, alt, legende, copyright, titre, createur, keywords FROM photos WHERE id >= ? AND id <= ? ORDER BY date DESC";
|
||||
$query4 = "SELECT filename, date, lens, exposure, iso, width, height, html, aperture, model, lat, long, alt, legende, copyright, titre, createur, keywords FROM photos WHERE id > ? ORDER BY date DESC";
|
||||
//$query4 = "SELECT filename, date, lens, exposure, iso, width, height, html, aperture, model, lat, long, alt, legende, copyright, titre, createur, keywords FROM photos WHERE lat != '' OR long != '' ORDER BY date DESC";
|
||||
|
||||
$stmt = $conn4->prepare($query4);
|
||||
$stmt = $conn->prepare($query4);
|
||||
$stmt->bindValue(1, $nb_avant, SQLITE3_INTEGER); // (1,3...) 1=1ere valeur 3=valeur
|
||||
# id 1 -> 3
|
||||
$stmt->execute(array(1, 3));
|
||||
//$stmt->execute(array(1, 3)); // WHERE id >= ? AND id <= ? ORDER BY date DESC";
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
_pr($result);
|
||||
//$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
//_pr($result);
|
||||
|
||||
echo '<h3>Lecture des photos ajoutées:</h3>';
|
||||
echo '<div id="add_to_bdd">';
|
||||
echo '<table class="styled-table">';
|
||||
echo '<thead>';
|
||||
echo '<th>Thumb</th><th>Filename</th><th>Date</th><th>Lens</th><th>Exposure</th><th>Iso</th><th>Width</th><th>Height</th><th>Html</th><th>Aperture</th><th>Model</th><th>Lat</th><th>Long</th><th>Alt</th><th>Legende</th><th>Copyright</th><th>Titre</th><th>Createur</th><th>Keywords</th>';
|
||||
echo '</thead>';
|
||||
echo '<tbody>';
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$thumbnail = host() . str_replace("photos/img", "photos/thumb", $row['filename']);
|
||||
$full = host() . $row['filename'];
|
||||
//echo ' | ' . $row['filename'] . ' | ' . $row['date'] . ' | ' . $row['lens'] . ' | ' . $row['exposure'] . ' | ' . $row['iso'] . ' | ' . $row['width'] . ' | ' . $row['height'] . ' | ' . $row['html'] . ' | ' . $row['aperture'] . ' | ' . $row['model'] . ' | ' . $row['lat'] . ' | ' . $row['long'] . ' | ' . $row['alt'] . ' | ' . $row['legende'] . ' | ' . $row['copyright'] . ' | ' . $row['titre'] . ' | ' . $row['createur'] . " |\r\n";
|
||||
echo '<tr><td>' . '<a href="' . $full . '"><img src="'.$thumbnail.'" /></a>' . '</td><td>' . $row['filename'] . '</td><td>' . $row['date'] . '</td><td>' . $row['lens'] . '</td><td>' . $row['exposure'] . '</td><td>' . $row['iso'] . '</td><td>' . $row['width'] . '</td><td>' . $row['height'] . '</td><td>' . $row['html'] . '</td><td>' . $row['aperture'] . '</td><td>' . $row['model'] . '</td><td>' . $row['lat'] . '</td><td>' . $row['long'] . '</td><td>' . $row['alt'] . '</td><td>' . $row['legende'] . '</td><td>' . $row['copyright'] . '</td><td>' . $row['titre'] . '</td><td>' . $row['createur'] . '</td><td>' . $row['keywords'] . '</td></tr>';
|
||||
}
|
||||
echo '</tbody></table>';
|
||||
echo '</div>';
|
||||
|
||||
$conn4 = null;
|
||||
$conn = null;
|
||||
}
|
||||
catch(PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
?>
|
||||
|
||||
?>
|
||||
<script type='text/javascript'>
|
||||
$(document).ready(function() {
|
||||
|
||||
var $obj = lc_lightbox('#add_to_bdd a', {
|
||||
open_close_time : 200,
|
||||
ol_time_diff : 100,
|
||||
wrap_class : 'lcl_zoomin_oc',
|
||||
skin : 'minimal',
|
||||
txt_hidden : true,
|
||||
fullscreen : false,
|
||||
fs_img_behavior : 'smart',
|
||||
browser_fs_mode : true,
|
||||
rclick_prevent : true,
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<script src='js/lc_lightbox.min.js' type='text/javascript'></script>
|
||||
<script src='js/alloy_finger.min.js' type='text/javascript'></script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user