diff --git a/classes/Tools.php b/classes/Tools.php index 7617ddec1..30cff6c8a 100644 --- a/classes/Tools.php +++ b/classes/Tools.php @@ -1313,9 +1313,30 @@ class ToolsCore { return @simplexml_load_string(Tools::file_get_contents($url), $class_name); } + + public static function copy($source, $destination, $stream_context = null) + { + if ($stream_context == null && preg_match('/^https?:\/\//', $source)) + $stream_context = @stream_context_create(array('http' => array('timeout' => 10))); - - public static $a = 0; + if (in_array(@ini_get('allow_url_fopen'), array('On', 'on', '1')) || !preg_match('/^https?:\/\//', $source)) + return @copy($source, $destination, $stream_context); + elseif (function_exists('curl_init')) + { + $curl = curl_init(); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_URL, $source); + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); + curl_setopt($curl, CURLOPT_TIMEOUT, 10); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + $opts = stream_context_get_options($stream_context); + $content = curl_exec($curl); + curl_close($curl); + return file_put_contents($content, $destination); + } + else + return false; + } /** * @deprecated as of 1.5 use Media::minifyHTML() diff --git a/controllers/admin/AdminImportController.php b/controllers/admin/AdminImportController.php index 2bf3a7aa5..4caac1013 100644 --- a/controllers/admin/AdminImportController.php +++ b/controllers/admin/AdminImportController.php @@ -819,7 +819,7 @@ class AdminImportControllerCore extends AdminController // 'file_exists' doesn't work on distant file, and getimagesize make the import slower. // Just hide the warning, the traitment will be the same. - if (@copy($url, $tmpfile)) + if (Tools::copy($url, $tmpfile)) { ImageManager::resize($tmpfile, $path.'.jpg'); $images_types = ImageType::getImagesTypes($entity);