diff --git a/admin-dev/themes/default/template/helpers/uploader/ajax.tpl b/admin-dev/themes/default/template/helpers/uploader/ajax.tpl
index 68a240124..e5ae31901 100644
--- a/admin-dev/themes/default/template/helpers/uploader/ajax.tpl
+++ b/admin-dev/themes/default/template/helpers/uploader/ajax.tpl
@@ -43,6 +43,18 @@
{/if}
+{if isset($max_files) && $files|count >= $max_files}
+
+
{l s='You have reached the limit (%s) of files to upload, please remove files to continue uploading' sprintf=$max_files}
+
+
+{else}
-
- {l s='Files:'}
-
-
+
+
+
-
\ No newline at end of file
+ {$id}_total_files++;
+ }).on('fileuploadprocessalways', function (e, data) {
+ var index = data.index, file = data.files[index];
+
+ if (file.error) {
+ $('#{$id}-errors').append(''+file.name+' ('+humanizeSize(file.size)+') : '+file.error+'
').parent().show();
+ $(data.context).find('button').trigger('click');
+ }
+ });
+
+ $('#{$id}-add-button').on('click', function() {
+ $('#{$id}-success').html('').parent().hide();
+ $('#{$id}-errors').html('').parent().hide();
+ $('#{$id}-files-list').html('').parent().hide();
+ {$id}_total_files = 0;
+ $('#{$id}').trigger('click');
+ });
+ });
+
+{/if}
\ No newline at end of file
diff --git a/admin-dev/themes/default/template/helpers/uploader/simple.tpl b/admin-dev/themes/default/template/helpers/uploader/simple.tpl
index e5f386a5a..0c1510d3e 100644
--- a/admin-dev/themes/default/template/helpers/uploader/simple.tpl
+++ b/admin-dev/themes/default/template/helpers/uploader/simple.tpl
@@ -50,6 +50,11 @@
{/if}
+{if isset($max_files) && $files|count >= $max_files}
+
+
{l s='You have reached the limit (%s) of files to upload, please remove files to continue uploading' sprintf=$max_files}
+
+{else}
-
\ No newline at end of file
+
+{/if}
\ No newline at end of file
diff --git a/classes/Uploader.php b/classes/Uploader.php
index 8152dab70..c36036eea 100644
--- a/classes/Uploader.php
+++ b/classes/Uploader.php
@@ -48,9 +48,6 @@ class UploaderCore
public function getAcceptTypes()
{
- if (!isset($this->_accept_types))
- $this->setAcceptTypes('/.+$/i');
-
return $this->_accept_types;
}
@@ -101,6 +98,21 @@ class UploaderCore
return $this;
}
+ public function getPostMaxSizeBytes() {
+ $post_max_size = ini_get('post_max_size');
+ $bytes = trim($post_max_size);
+ $last = strtolower($post_max_size[strlen($post_max_size) - 1]);
+
+ switch ($last)
+ {
+ case 'g': $bytes *= 1024;
+ case 'm': $bytes *= 1024;
+ case 'k': $bytes *= 1024;
+ }
+
+ return $bytes;
+ }
+
public function getSavePath()
{
if (!isset($this->_save_path))
@@ -134,8 +146,11 @@ class UploaderCore
$this->files[] = $this->upload($tmp[$index]);
}
}
- else
+ elseif ($upload)
+ {
+
$this->files[] = $this->upload($upload);
+ }
return $this->files;
}
@@ -173,7 +188,7 @@ class UploaderCore
protected function validate($file)
{
- $post_max_size = $this->_getPostMaxSizeBytes();
+ $post_max_size = $this->getPostMaxSizeBytes();
if ($post_max_size && ($this->_getServerVars('CONTENT_LENGTH') > $post_max_size))
{
@@ -181,7 +196,10 @@ class UploaderCore
return false;
}
- if (!preg_match($this->getAcceptTypes(), $file['name']))
+ $types = $this->getAcceptTypes();
+
+ //TODO check mime type.
+ if (isset($types) && !in_array(pathinfo($file['name'], PATHINFO_EXTENSION), $types))
{
$file['error'] = Tools::displayError('Filetype not allowed');
return false;
@@ -203,21 +221,6 @@ class UploaderCore
return filesize($file_path);
}
- protected function _getPostMaxSizeBytes() {
- $post_max_size = ini_get('post_max_size');
- $bytes = trim($post_max_size);
- $last = strtolower($post_max_size[strlen($post_max_size) - 1]);
-
- switch ($last)
- {
- case 'g': $bytes *= 1024;
- case 'm': $bytes *= 1024;
- case 'k': $bytes *= 1024;
- }
-
- return $bytes;
- }
-
protected function _getServerVars($var)
{
return (isset($_SERVER[$var]) ? $_SERVER[$var] : '');
diff --git a/classes/helper/HelperForm.php b/classes/helper/HelperForm.php
index f406e2ee9..0c8554a4a 100644
--- a/classes/helper/HelperForm.php
+++ b/classes/helper/HelperForm.php
@@ -118,6 +118,7 @@ class HelperFormCore extends Helper
$uploader->setUrl(isset($params['url'])?$params['url']:null);
$uploader->setMultiple(isset($params['multiple'])?$params['multiple']:false);
$uploader->setUseAjax(isset($params['ajax'])?$params['ajax']:false);
+ $uploader->setMaxFiles(isset($params['max_files'])?$params['max_files']:null);
if (isset($params['files']) && $params['files'])
$uploader->setFiles($params['files']);
@@ -139,7 +140,6 @@ class HelperFormCore extends Helper
'download_url' => isset($params['file'])?$params['file']:null
)));
-
$uploader->setThumb(isset($params['thumb'])?$params['thumb']:null);
$uploader->setTitle(isset($params['title'])?$params['title']:null);
diff --git a/classes/helper/HelperImageUploader.php b/classes/helper/HelperImageUploader.php
index 830a6b92d..708d420f7 100644
--- a/classes/helper/HelperImageUploader.php
+++ b/classes/helper/HelperImageUploader.php
@@ -26,35 +26,25 @@
class HelperImageUploaderCore extends HelperUploader
{
- private $_temporary_path;
-
public function getMaxSize()
{
return (int)Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE');
}
- public function setTemporaryPath($value)
+ public function getSavePath()
{
- $this->_temporary_path = $value;
- }
-
- public function getTemporaryPath()
- {
- if (!isset($this->_temporary_path))
- $this->_temporary_path = _PS_TMP_IMG_DIR_;
-
- return $this->_normalizeDirectory($this->_temporary_path);
+ return $this->_normalizeDirectory(_PS_TMP_IMG_DIR_);
}
public function getFilePath($file_name = null)
{
//Force file path
- return tempnam($this->getTemporaryPath(), $this->getUniqueFileName());
+ return tempnam($this->getSavePath(), $this->getUniqueFileName());
}
protected function validate($file)
{
- $post_max_size = $this->_getPostMaxSizeBytes();
+ $post_max_size = $this->getPostMaxSizeBytes();
if ($post_max_size && ($this->_getServerVars('CONTENT_LENGTH') > $post_max_size))
{
@@ -62,7 +52,10 @@ class HelperImageUploaderCore extends HelperUploader
return false;
}
- if (!preg_match($this->getAcceptTypes(), $file['name']))
+ $types = $this->getAcceptTypes();
+
+ //TODO check mime type.
+ if (isset($types) && !in_array(pathinfo($file['name'], PATHINFO_EXTENSION), $types))
{
$file['error'] = Tools::displayError('Filetype not allowed');
return false;
diff --git a/classes/helper/HelperOptions.php b/classes/helper/HelperOptions.php
index 2a4b142d9..e17667357 100644
--- a/classes/helper/HelperOptions.php
+++ b/classes/helper/HelperOptions.php
@@ -104,6 +104,7 @@ class HelperOptionsCore extends Helper
$uploader->setUrl(isset($field['url'])?$field['url']:null);
$uploader->setMultiple(isset($field['multiple'])?$field['multiple']:false);
$uploader->setUseAjax(isset($field['ajax'])?$field['ajax']:false);
+ $uploader->setMaxFiles(isset($field['max_files'])?$field['max_files']:null);
if (isset($field['files']) && $field['files'])
$uploader->setFiles($field['files']);
diff --git a/classes/helper/HelperUploader.php b/classes/helper/HelperUploader.php
index 276f08ba3..daea1b146 100644
--- a/classes/helper/HelperUploader.php
+++ b/classes/helper/HelperUploader.php
@@ -243,22 +243,28 @@ class HelperUploaderCore extends Uploader
.'/themes/'.$bo_theme.'/js/vendor/jquery.ui.widget.js">';
$html .= '';
- $html .= '';
+ $html .= '';
+ $html .= '';
+ $html .= '';
+ $html .= '';
}
else
{
$html = '';
$this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/vendor/jquery.ui.widget.js');
- //$context->controller->addJs('http://blueimp.github.io/JavaScript-Load-Image/js/load-image.min.js');
$this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/jquery.iframe-transport.js');
$this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/jquery.fileupload.js');
- /*$context->controller->addJs(__PS_BASE_URI__.$admin_webpath
- .'/themes/'.$bo_theme.'/js/jquery.fileupload-image.js');*/
-
+ $this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath
+ .'/themes/'.$bo_theme.'/js/jquery.fileupload-process.js');
+ $this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath
+ .'/themes/'.$bo_theme.'/js/jquery.fileupload-validate.js');
$this->getContext()->controller->addJs(__PS_BASE_URI__.'/js/vendor/spin.js');
$this->getContext()->controller->addJs(__PS_BASE_URI__.'/js/vendor/ladda.js');
}
@@ -270,8 +276,6 @@ class HelperUploaderCore extends Uploader
$this->getTemplateFile($this->getTemplate()), $this->getContext()->smarty
);
- $max_files = $this->getMaxFiles();
-
$template->assign(array(
'id' => $this->getId(),
'name' => $this->getName(),
@@ -280,7 +284,8 @@ class HelperUploaderCore extends Uploader
'files' => $this->getFiles(),
'thumb' => $this->getThumb(),
'title' => $this->getTitle(),
- 'max_files' => (isset($max_files) && $max_files > 0) ? ($max_files-count($this->getFiles())) : $max_files
+ 'max_files' => $this->getMaxFiles(),
+ 'post_max_size' => $this->getPostMaxSizeBytes()
));
$html .= $template->fetch();