[-] BO : fixed image import with allow_url_fopen deactivated #PSCFV-8181

This commit is contained in:
Damien Metzger
2013-04-29 17:11:17 +02:00
parent 88adba8e5b
commit 989b19d94a
2 changed files with 24 additions and 3 deletions
+23 -2
View File
@@ -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()
+1 -1
View File
@@ -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);