From 1dece874347e63c340fdae043f79e57fbaa2072b Mon Sep 17 00:00:00 2001 From: Tobias Reich Date: Sun, 28 Jun 2015 18:58:17 +0200 Subject: [PATCH] Fixed: Only import urls passend to the function, not existing photos from the temp folder --- php/modules/Import.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/php/modules/Import.php b/php/modules/Import.php index 618e39d..7ab2da9 100644 --- a/php/modules/Import.php +++ b/php/modules/Import.php @@ -32,6 +32,8 @@ class Import extends Module { static function url($urls, $albumID = 0) { + global $database, $plugins, $settings; + $error = false; # Parse @@ -40,6 +42,9 @@ class Import extends Module { foreach ($urls as &$url) { + # Validate photo type and extension even when Import::photo (=> $photo->add) will do the same. + # This prevents us from downloading invalid photos. + # Verify extension $extension = getExtension($url); if (!in_array(strtolower($extension), Photo::$validExtensions, true)) { @@ -58,14 +63,23 @@ class Import extends Module { $filename = $pathinfo['filename'] . '.' . $pathinfo['extension']; $tmp_name = LYCHEE_DATA . $filename; - if (@copy($url, $tmp_name)===false) $error = true; + if (@copy($url, $tmp_name)===false) { + $error = true; + Log::error($database, __METHOD__, __LINE__, 'Could not copy file (' . $tmp_name . ') to temp-folder (' . $tmp_name . ')'); + continue; + } + + # Import photo + if (!Import::photo($database, $plugins, $settings, $tmp_name, $albumID)) { + $error = true; + Log::error($database, __METHOD__, __LINE__, 'Could not import file: ' . $tmp_name); + continue; + } } - $import = Import::server($albumID, LYCHEE_DATA); - - if ($error===false&&$import===true) return true; - else return false; + if ($error===false) return true; + return false; }