Don't reupload duplicates (#48)
This commit is contained in:
parent
b4eccb6215
commit
e942c9c525
@ -96,10 +96,39 @@ class Photo extends Module {
|
||||
$id = str_replace('.', '', microtime(true));
|
||||
while(strlen($id)<14) $id .= 0;
|
||||
|
||||
# Set paths
|
||||
$tmp_name = $file['tmp_name'];
|
||||
$photo_name = md5($id) . $extension;
|
||||
$path = LYCHEE_UPLOADS_BIG . $photo_name;
|
||||
|
||||
# Calculate checksum
|
||||
$checksum = sha1_file($tmp_name);
|
||||
|
||||
# Check if image exists based on checksum
|
||||
if ($checksum===false) {
|
||||
|
||||
$checksum = '';
|
||||
$exists = false;
|
||||
|
||||
} else {
|
||||
|
||||
$query = "SELECT id, url, thumbUrl FROM lychee_photos WHERE checksum = '$checksum' LIMIT 1;";
|
||||
$result = $this->database->query($query);
|
||||
|
||||
if ($result->num_rows===1) {
|
||||
$result = $result->fetch_assoc();
|
||||
$photo_name = $result['url'];
|
||||
$path = LYCHEE_UPLOADS_BIG . $result['url'];
|
||||
$path_thumb = $result['thumbUrl'];
|
||||
$exists = true;
|
||||
} else {
|
||||
$exists = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($exists===false) {
|
||||
|
||||
# Import if not uploaded via web
|
||||
if (!is_uploaded_file($tmp_name)) {
|
||||
if (!@copy($tmp_name, $path)) {
|
||||
@ -113,9 +142,7 @@ class Photo extends Module {
|
||||
}
|
||||
}
|
||||
|
||||
# Calculate checksum
|
||||
$checksum = sha1_file($path);
|
||||
if ($checksum===false) $checksum = '';
|
||||
}
|
||||
|
||||
# Read infos
|
||||
$info = $this->getInfo($path);
|
||||
@ -126,6 +153,8 @@ class Photo extends Module {
|
||||
# Use description parameter if set
|
||||
if ($description==='') $description = $info['description'];
|
||||
|
||||
if ($exists===false) {
|
||||
|
||||
# Set orientation based on EXIF data
|
||||
if ($file['type']==='image/jpeg'&&isset($info['orientation'])&&$info['orientation']!==''&&isset($info['width'])&&isset($info['height'])) {
|
||||
if (!$this->adjustFile($path, $info)) Log::notice($this->database, __METHOD__, __LINE__, 'Could not adjust photo (' . $info['title'] . ')');
|
||||
@ -140,6 +169,11 @@ class Photo extends Module {
|
||||
exit('Error: Could not create thumbnail for photo!');
|
||||
}
|
||||
|
||||
# Set thumb url
|
||||
$path_thumb = md5($id) . '.jpeg';
|
||||
|
||||
}
|
||||
|
||||
# Save to DB
|
||||
$query = "INSERT INTO lychee_photos (id, title, url, description, tags, type, width, height, size, iso, aperture, make, model, shutter, focal, takestamp, thumbUrl, album, public, star, checksum)
|
||||
VALUES (
|
||||
@ -159,7 +193,7 @@ class Photo extends Module {
|
||||
'" . $info['shutter'] . "',
|
||||
'" . $info['focal'] . "',
|
||||
'" . $info['takestamp'] . "',
|
||||
'" . md5($id) . ".jpeg',
|
||||
'" . $path_thumb . "',
|
||||
'" . $albumID . "',
|
||||
'" . $public . "',
|
||||
'" . $star . "',
|
||||
|
Loading…
Reference in New Issue
Block a user