2014-01-22 10:12:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2014-02-17 16:01:46 +00:00
|
|
|
* @name Upload Module
|
|
|
|
* @author Philipp Maurer
|
|
|
|
* @author Tobias Reich
|
|
|
|
* @copyright 2014 by Philipp Maurer, Tobias Reich
|
2014-01-22 10:12:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
|
|
|
|
2014-03-31 12:51:47 +00:00
|
|
|
function upload($files, $albumID, $description = '', $tags = '') {
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-01-31 22:55:16 +00:00
|
|
|
global $database, $settings;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
switch($albumID) {
|
|
|
|
// s for public (share)
|
2014-02-17 16:01:46 +00:00
|
|
|
case 's':
|
|
|
|
$public = 1;
|
|
|
|
$star = 0;
|
|
|
|
$albumID = 0;
|
|
|
|
break;
|
|
|
|
// f for starred (fav)
|
|
|
|
case 'f':
|
|
|
|
$star = 1;
|
|
|
|
$public = 0;
|
|
|
|
$albumID = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$star = 0;
|
|
|
|
$public = 0;
|
2014-01-22 10:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($files as $file) {
|
2014-02-17 16:01:46 +00:00
|
|
|
|
|
|
|
if ($file['type']!=='image/jpeg'&&
|
|
|
|
$file['type']!=='image/png'&&
|
|
|
|
$file['type']!=='image/gif')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$id = str_replace('.', '', microtime(true));
|
|
|
|
while(strlen($id)<14) $id .= 0;
|
|
|
|
|
|
|
|
$tmp_name = $file['tmp_name'];
|
|
|
|
$extension = array_reverse(explode('.', $file['name']));
|
|
|
|
$extension = $extension[0];
|
|
|
|
$photo_name = md5($id) . ".$extension";
|
|
|
|
|
|
|
|
// Import if not uploaded via web
|
|
|
|
if (!is_uploaded_file($tmp_name)) {
|
2014-04-09 18:37:01 +00:00
|
|
|
if (copy($tmp_name, __DIR__ . '/../../uploads/big/' . $photo_name)) {
|
2014-02-09 21:30:16 +00:00
|
|
|
@unlink($tmp_name);
|
2014-01-22 10:12:51 +00:00
|
|
|
$import_name = $tmp_name;
|
|
|
|
}
|
2014-02-17 16:01:46 +00:00
|
|
|
} else {
|
2014-04-09 18:37:01 +00:00
|
|
|
move_uploaded_file($tmp_name, __DIR__ . '/../../uploads/big/' . $photo_name);
|
2014-02-17 16:01:46 +00:00
|
|
|
$import_name = '';
|
|
|
|
}
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
// Read infos
|
|
|
|
$info = getInfo($photo_name);
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
// Use title of file if IPTC title missing
|
2014-03-31 12:51:47 +00:00
|
|
|
if ($info['title']==='') $info['title'] = mysqli_real_escape_string($database, substr(basename($file['name'], ".$extension"), 0, 30));
|
|
|
|
|
|
|
|
// Use description parameter if set
|
|
|
|
if ($description==='') $description = $info['description'];
|
2014-01-31 22:55:16 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
// Set orientation based on EXIF data
|
2014-04-11 08:38:35 +00:00
|
|
|
if ($file['type']==='image/jpeg'&&isset($info['orientation'])&&isset($info['width'])&&isset($info['height'])) {
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-04-10 22:24:06 +00:00
|
|
|
if(extension_loaded('imagick')) {
|
2014-04-09 18:37:01 +00:00
|
|
|
|
|
|
|
$rotateImage = 0;
|
|
|
|
|
|
|
|
switch ($info['orientation']) {
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
$rotateImage = 180;
|
|
|
|
$imageOrientation = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
$rotateImage = 90;
|
|
|
|
$imageOrientation = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
$rotateImage = 270;
|
|
|
|
$imageOrientation = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($rotateImage) {
|
|
|
|
$image = new Imagick();
|
|
|
|
$image->readImage(__DIR__ . '/../../uploads/big/' . $photo_name);
|
|
|
|
$image->rotateImage(new ImagickPixel(), $rotateImage);
|
|
|
|
$image->setImageOrientation($imageOrientation);
|
|
|
|
$image->writeImage(__DIR__ . '/../../uploads/big/' . $photo_name);
|
|
|
|
$image->clear();
|
|
|
|
$image->destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
$newWidth = $info['width'];
|
|
|
|
$newHeight = $info['height'];
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-04-09 18:37:01 +00:00
|
|
|
$sourceImg = imagecreatefromjpeg(__DIR__ . "/../../uploads/big/$photo_name");
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-04-09 18:37:01 +00:00
|
|
|
switch ($info['orientation']) {
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
case 2:
|
|
|
|
// mirror
|
|
|
|
// not yet implemented
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
$sourceImg = imagerotate($sourceImg, -180, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
// rotate 180 and mirror
|
|
|
|
// not yet implemented
|
2014-02-17 16:01:46 +00:00
|
|
|
break;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
case 5:
|
|
|
|
// rotate 90 and mirror
|
|
|
|
// not yet implemented
|
2014-02-17 16:01:46 +00:00
|
|
|
break;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
case 6:
|
|
|
|
$sourceImg = imagerotate($sourceImg, -90, 0);
|
|
|
|
$newWidth = $info['height'];
|
|
|
|
$newHeight = $info['width'];
|
2014-02-17 16:01:46 +00:00
|
|
|
break;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
case 7:
|
|
|
|
// rotate -90 and mirror
|
|
|
|
// not yet implemented
|
2014-02-17 16:01:46 +00:00
|
|
|
break;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
case 8:
|
|
|
|
$sourceImg = imagerotate($sourceImg, 90, 0);
|
|
|
|
$newWidth = $info['height'];
|
|
|
|
$newHeight = $info['width'];
|
2014-02-17 16:01:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$newSourceImg = imagecreatetruecolor($newWidth, $newHeight);
|
|
|
|
|
|
|
|
imagecopyresampled($newSourceImg, $sourceImg, 0, 0, 0, 0, $newWidth, $newHeight, $newWidth, $newHeight);
|
2014-04-09 18:37:01 +00:00
|
|
|
imagejpeg($newSourceImg, __DIR__ . '/../../uploads/big/' . $photo_name, 100);
|
2014-02-17 16:01:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create Thumb
|
|
|
|
if (!createThumb($photo_name)) return false;
|
|
|
|
|
|
|
|
// Save to DB
|
2014-04-11 08:09:06 +00:00
|
|
|
$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, import_name)
|
2014-02-17 16:01:46 +00:00
|
|
|
VALUES (
|
|
|
|
'" . $id . "',
|
|
|
|
'" . $info['title'] . "',
|
|
|
|
'" . $photo_name . "',
|
2014-03-31 12:51:47 +00:00
|
|
|
'" . $description . "',
|
|
|
|
'" . $tags . "',
|
2014-02-17 16:01:46 +00:00
|
|
|
'" . $info['type'] . "',
|
|
|
|
'" . $info['width'] . "',
|
|
|
|
'" . $info['height'] . "',
|
|
|
|
'" . $info['size'] . "',
|
|
|
|
'" . $info['iso'] . "',
|
|
|
|
'" . $info['aperture'] . "',
|
|
|
|
'" . $info['make'] . "',
|
|
|
|
'" . $info['model'] . "',
|
|
|
|
'" . $info['shutter'] . "',
|
|
|
|
'" . $info['focal'] . "',
|
2014-04-11 08:09:06 +00:00
|
|
|
'" . $info['takestamp'] . "',
|
2014-02-17 16:01:46 +00:00
|
|
|
'" . md5($id) . ".jpeg',
|
|
|
|
'" . $albumID . "',
|
|
|
|
'" . $public . "',
|
|
|
|
'" . $star . "',
|
|
|
|
'" . $import_name . "');";
|
|
|
|
$result = $database->query($query);
|
|
|
|
|
|
|
|
if (!$result) return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function getInfo($filename) {
|
|
|
|
|
|
|
|
global $database;
|
|
|
|
|
2014-04-09 18:37:01 +00:00
|
|
|
$url = __DIR__ . '/../../uploads/big/' . $filename;
|
2014-02-09 21:30:16 +00:00
|
|
|
$iptcArray = array();
|
|
|
|
$info = getimagesize($url, $iptcArray);
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
// General information
|
2014-02-09 21:30:16 +00:00
|
|
|
$return['type'] = $info['mime'];
|
|
|
|
$return['width'] = $info[0];
|
|
|
|
$return['height'] = $info[1];
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
// Size
|
|
|
|
$size = filesize($url)/1024;
|
|
|
|
if ($size>=1024) $return['size'] = round($size/1024, 1) . ' MB';
|
|
|
|
else $return['size'] = round($size, 1) . ' KB';
|
|
|
|
|
|
|
|
// IPTC Metadata Fallback
|
2014-02-09 21:30:16 +00:00
|
|
|
$return['title'] = '';
|
|
|
|
$return['description'] = '';
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
// IPTC Metadata
|
2014-01-26 14:16:59 +00:00
|
|
|
if(isset($iptcArray['APP13'])) {
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-01-26 14:16:59 +00:00
|
|
|
$iptcInfo = iptcparse($iptcArray['APP13']);
|
|
|
|
if (is_array($iptcInfo)) {
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-02-09 21:30:16 +00:00
|
|
|
$temp = @$iptcInfo['2#105'][0];
|
2014-01-26 14:16:59 +00:00
|
|
|
if (isset($temp)&&strlen($temp)>0) $return['title'] = $temp;
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-02-09 21:30:16 +00:00
|
|
|
$temp = @$iptcInfo['2#120'][0];
|
2014-01-26 14:16:59 +00:00
|
|
|
if (isset($temp)&&strlen($temp)>0) $return['description'] = $temp;
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-01-26 14:16:59 +00:00
|
|
|
}
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EXIF Metadata Fallback
|
2014-02-09 21:30:16 +00:00
|
|
|
$return['orientation'] = '';
|
|
|
|
$return['iso'] = '';
|
|
|
|
$return['aperture'] = '';
|
|
|
|
$return['make'] = '';
|
|
|
|
$return['model'] = '';
|
|
|
|
$return['shutter'] = '';
|
|
|
|
$return['focal'] = '';
|
2014-04-11 08:09:06 +00:00
|
|
|
$return['takestamp'] = '';
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-02-09 21:30:16 +00:00
|
|
|
// Read EXIF
|
2014-03-18 22:01:08 +00:00
|
|
|
if ($info['mime']=='image/jpeg') $exif = @exif_read_data($url, 'EXIF', 0);
|
2014-02-09 21:30:16 +00:00
|
|
|
else $exif = false;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
// EXIF Metadata
|
2014-02-17 16:01:46 +00:00
|
|
|
if ($exif!==false) {
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-04-09 18:37:01 +00:00
|
|
|
if (isset($exif['Orientation'])) $return['orientation'] = $exif['Orientation'];
|
|
|
|
else if (isset($exif['IFD0']['Orientation'])) $return['orientation'] = $exif['IFD0']['Orientation'];
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
$temp = @$exif['ISOSpeedRatings'];
|
|
|
|
if (isset($temp)) $return['iso'] = $temp;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
$temp = @$exif['COMPUTED']['ApertureFNumber'];
|
|
|
|
if (isset($temp)) $return['aperture'] = $temp;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
$temp = @$exif['Make'];
|
|
|
|
if (isset($temp)) $return['make'] = $exif['Make'];
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
$temp = @$exif['Model'];
|
|
|
|
if (isset($temp)) $return['model'] = $temp;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
$temp = @$exif['ExposureTime'];
|
|
|
|
if (isset($temp)) $return['shutter'] = $exif['ExposureTime'] . ' Sec.';
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
$temp = @$exif['FocalLength'];
|
|
|
|
if (isset($temp)) $return['focal'] = ($temp/1) . ' mm';
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
$temp = @$exif['DateTimeOriginal'];
|
2014-04-11 08:09:06 +00:00
|
|
|
if (isset($temp)) $return['takestamp'] = strtotime($temp);
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
}
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
// Security
|
|
|
|
foreach(array_keys($return) as $key) $return[$key] = mysqli_real_escape_string($database, $return[$key]);
|
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
return $return;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function createThumb($filename, $width = 200, $height = 200) {
|
|
|
|
|
|
|
|
global $settings;
|
|
|
|
|
2014-04-09 18:37:01 +00:00
|
|
|
$url = __DIR__ . '/../../uploads/big/' . $filename;
|
|
|
|
$info = getimagesize($url);
|
2014-02-17 16:01:46 +00:00
|
|
|
|
|
|
|
$photoName = explode(".", $filename);
|
2014-04-09 18:37:01 +00:00
|
|
|
$newUrl = __DIR__ . '/../../uploads/thumb/' . $photoName[0] . '.jpeg';
|
|
|
|
$newUrl2x = __DIR__ . '/../../uploads/thumb/' . $photoName[0] . '@2x.jpeg';
|
|
|
|
|
|
|
|
// create thumbnails with Imagick
|
2014-04-10 22:24:06 +00:00
|
|
|
if(extension_loaded('imagick')) {
|
2014-04-09 18:37:01 +00:00
|
|
|
|
|
|
|
// read image
|
|
|
|
$thumb = new Imagick();
|
|
|
|
$thumb->readImage($url);
|
|
|
|
$thumb->setImageCompressionQuality($settings['thumbQuality']);
|
|
|
|
$thumb->setImageFormat('jpeg');
|
|
|
|
|
|
|
|
// copy image for 2nd thumb version
|
|
|
|
$thumb2x = clone $thumb;
|
|
|
|
|
|
|
|
// creat 1st version
|
|
|
|
$thumb->cropThumbnailImage($width, $height);
|
|
|
|
$thumb->writeImage($newUrl);
|
|
|
|
|
|
|
|
// creat 2nd version
|
|
|
|
$thumb2x->cropThumbnailImage($width*2, $height*2);
|
|
|
|
$thumb2x->writeImage($newUrl2x);
|
|
|
|
|
|
|
|
// close thumb
|
|
|
|
$thumb->clear();
|
|
|
|
$thumb->destroy();
|
|
|
|
|
|
|
|
// close thumb2
|
|
|
|
$thumb2x->clear();
|
|
|
|
$thumb2x->destroy();
|
|
|
|
|
2014-02-17 16:01:46 +00:00
|
|
|
} else {
|
|
|
|
|
2014-04-09 18:37:01 +00:00
|
|
|
// Set position and size
|
|
|
|
$thumb = imagecreatetruecolor($width, $height);
|
|
|
|
$thumb2x = imagecreatetruecolor($width*2, $height*2);
|
|
|
|
if ($info[0]<$info[1]) {
|
|
|
|
$newSize = $info[0];
|
|
|
|
$startWidth = 0;
|
|
|
|
$startHeight = $info[1]/2 - $info[0]/2;
|
|
|
|
} else {
|
|
|
|
$newSize = $info[1];
|
|
|
|
$startWidth = $info[0]/2 - $info[1]/2;
|
|
|
|
$startHeight = 0;
|
|
|
|
}
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-04-09 18:37:01 +00:00
|
|
|
// Fallback for older version
|
|
|
|
if ($info['mime']==='image/webp'&&floatval(phpversion())<5.5) return false;
|
|
|
|
|
|
|
|
// Create new image
|
|
|
|
switch($info['mime']) {
|
|
|
|
case 'image/jpeg': $sourceImg = imagecreatefromjpeg($url); break;
|
|
|
|
case 'image/png': $sourceImg = imagecreatefrompng($url); break;
|
|
|
|
case 'image/gif': $sourceImg = imagecreatefromgif($url); break;
|
|
|
|
case 'image/webp': $sourceImg = imagecreatefromwebp($url); break;
|
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
imagecopyresampled($thumb,$sourceImg,0,0,$startWidth,$startHeight,$width,$height,$newSize,$newSize);
|
|
|
|
imagecopyresampled($thumb2x,$sourceImg,0,0,$startWidth,$startHeight,$width*2,$height*2,$newSize,$newSize);
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-04-09 18:37:01 +00:00
|
|
|
imagejpeg($thumb,$newUrl,$settings['thumbQuality']);
|
|
|
|
imagejpeg($thumb2x,$newUrl2x,$settings['thumbQuality']);
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-04-09 18:37:01 +00:00
|
|
|
}
|
2014-02-17 16:01:46 +00:00
|
|
|
|
|
|
|
return true;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-03-31 12:51:47 +00:00
|
|
|
function importPhoto($path, $albumID = 0, $description = '', $tags = '') {
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-09 21:30:16 +00:00
|
|
|
$info = getimagesize($path);
|
|
|
|
$size = filesize($path);
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-02-09 21:30:16 +00:00
|
|
|
$nameFile = array(array());
|
|
|
|
$nameFile[0]['name'] = $path;
|
|
|
|
$nameFile[0]['type'] = $info['mime'];
|
|
|
|
$nameFile[0]['tmp_name'] = $path;
|
|
|
|
$nameFile[0]['error'] = 0;
|
|
|
|
$nameFile[0]['size'] = $size;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-03-31 12:51:47 +00:00
|
|
|
return upload($nameFile, $albumID, $description, $tags);
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function importUrl($url, $albumID = 0) {
|
|
|
|
|
|
|
|
if (strpos($url, ',')!==false) {
|
|
|
|
|
|
|
|
// Multiple photos
|
|
|
|
|
|
|
|
$url = explode(',', $url);
|
|
|
|
|
|
|
|
foreach ($url as &$key) {
|
|
|
|
|
|
|
|
$key = str_replace(' ', '%20', $key);
|
|
|
|
|
|
|
|
if (@getimagesize($key)) {
|
|
|
|
|
|
|
|
$pathinfo = pathinfo($key);
|
|
|
|
$filename = $pathinfo['filename'].".".$pathinfo['extension'];
|
2014-04-09 18:37:01 +00:00
|
|
|
$tmp_name = __DIR__ . '/../../uploads/import/' . $filename;
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
copy($key, $tmp_name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return importServer($albumID);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// One photo
|
|
|
|
|
|
|
|
$url = str_replace(' ', '%20', $url);
|
|
|
|
|
|
|
|
if (@getimagesize($url)) {
|
|
|
|
|
|
|
|
$pathinfo = pathinfo($url);
|
|
|
|
$filename = $pathinfo['filename'].".".$pathinfo['extension'];
|
2014-04-09 18:37:01 +00:00
|
|
|
$tmp_name = __DIR__ . "/../../uploads/import/$filename";
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
copy($url, $tmp_name);
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-02-26 22:37:21 +00:00
|
|
|
return importPhoto($tmp_name, $albumID);
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-04-09 18:37:01 +00:00
|
|
|
function importServer($albumID = 0, $path) {
|
|
|
|
|
|
|
|
if (!isset($path)) $path = __DIR__ . '/../../uploads/import/';
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
global $database;
|
|
|
|
|
2014-04-09 18:37:01 +00:00
|
|
|
$files = glob($path . '*');
|
|
|
|
$contains['photos'] = false;
|
|
|
|
$contains['albums'] = false;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
foreach ($files as $file) {
|
|
|
|
|
|
|
|
if (@getimagesize($file)) {
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-02-09 21:30:16 +00:00
|
|
|
// Photo
|
|
|
|
if (!importPhoto($file, $albumID)) return false;
|
|
|
|
$contains['photos'] = true;
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-02-09 21:30:16 +00:00
|
|
|
} else if (is_dir($file)) {
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-02-09 21:30:16 +00:00
|
|
|
$name = mysqli_real_escape_string($database, basename($file));
|
|
|
|
$newAlbumID = addAlbum('[Import] ' . $name);
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-02-09 21:30:16 +00:00
|
|
|
if ($newAlbumID!==false) importServer($newAlbumID, $file . '/');
|
|
|
|
$contains['albums'] = true;
|
2014-02-17 16:01:46 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-02-09 21:30:16 +00:00
|
|
|
if ($contains['photos']===false&&$contains['albums']===false) return "Warning: Folder empty!";
|
|
|
|
if ($contains['photos']===false&&$contains['albums']===true) return "Notice: Import only contains albums!";
|
2014-01-22 10:12:51 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|