From 18c6018b2429fdb6186a8f8c114547cd4f7131dc Mon Sep 17 00:00:00 2001 From: plegall Date: Tue, 29 Jun 2010 18:39:48 +0000 Subject: bug 1747 fixed: some checks were added to verify the upload will fail for a too big size or if the upload has failed for a too big size (test on upload_max_filesize and post_max_size) git-svn-id: http://piwigo.org/svn/branches/2.1@6624 68402e56-0260-453c-a942-63ccdbb3a9ee --- .../themes/default/template/photos_add_direct.tpl | 47 +++++++++++++++++----- 1 file changed, 37 insertions(+), 10 deletions(-) (limited to 'admin/themes') diff --git a/admin/themes/default/template/photos_add_direct.tpl b/admin/themes/default/template/photos_add_direct.tpl index ff1ada8e2..91d191ecb 100644 --- a/admin/themes/default/template/photos_add_direct.tpl +++ b/admin/themes/default/template/photos_add_direct.tpl @@ -49,6 +49,26 @@ jQuery(document).ready(function(){ } + function humanReadableFileSize(bytes) { + var byteSize = Math.round(bytes / 1024 * 100) * .01; + var suffix = 'KB'; + + if (byteSize > 1000) { + byteSize = Math.round(byteSize *.001 * 100) * .01; + suffix = 'MB'; + } + + var sizeParts = byteSize.toString().split('.'); + if (sizeParts.length > 1) { + byteSize = sizeParts[0] + '.' + sizeParts[1].substr(0,2); + } + else { + byteSize = sizeParts[0]; + } + + return byteSize+suffix; + } + if ($("select[name=category] option").length == 0) { $('input[name=category_type][value=existing]').attr('disabled', true); $('input[name=category_type]').attr('checked', false); @@ -90,6 +110,7 @@ var upload_id = '{$upload_id}'; var session_id = '{$session_id}'; var pwg_token = '{$pwg_token}'; var buttonText = 'Browse'; +var sizeLimit = {$upload_max_filesize}; {literal} jQuery("#uploadify").uploadify({ @@ -108,6 +129,7 @@ var buttonText = 'Browse'; 'multi' : true, 'fileDesc' : 'Photo files (*.jpg,*.jpeg,*.png)', 'fileExt' : '*.jpg;*.JPG;*.jpeg;*.JPEG;*.png;*.PNG', + 'sizeLimit' : sizeLimit, 'onAllComplete' : function(event, data) { if (data.errors) { return false; @@ -118,18 +140,23 @@ var buttonText = 'Browse'; }, onError: function (event, queueID ,fileObj, errorObj) { var msg; - if (errorObj.status == 404) { - alert('Could not find upload script.'); - msg = 'Could not find upload script.'; - } - else if (errorObj.type === "HTTP") { - msg = errorObj.type+": "+errorObj.status; + + if (errorObj.type === "HTTP") { + if (errorObj.info === 404) { + alert('Could not find upload script.'); + msg = 'Could not find upload script.'; + } + else { + msg = errorObj.type+": "+errorObj.info; + } } else if (errorObj.type ==="File Size") { - msg = fileObj.name+'
'+errorObj.type+' Limit: '+Math.round(errorObj.sizeLimit/1024)+'KB'; + msg = "File too big"; + msg = msg + '
'+fileObj.name+': '+humanReadableFileSize(fileObj.size); + msg = msg + '
Limit: '+humanReadableFileSize(sizeLimit); } else { - msg = errorObj.type+": "+errorObj.text; + msg = errorObj.type+": "+errorObj.info; } $.jGrowl( @@ -239,7 +266,7 @@ var buttonText = 'Browse'; -

{'Add another set of photos'|@translate}

+

{'Add another set of photos'|@translate}

{else} -
+
{'Drop into category'|@translate} {if $upload_mode eq 'multiple'} -- cgit v1.2.3