mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-22 10:08:45 +02:00
🐛 N°2072 Fix missing/empty error message when uploading too large attachment
This commit is contained in:
@@ -35,6 +35,7 @@ Dict::Add('EN US', 'English', 'English', array(
|
||||
'Attachment:Max_Ko' => '(Maximum file size: %1$s Ko)',
|
||||
'Attachments:NoAttachment' => 'No attachment. ',
|
||||
'Attachments:PreviewNotAvailable' => 'Preview not available for this type of attachment.',
|
||||
'Attachments:Error:FileTooLarge' => 'File is too large to be uploaded. %1$s',
|
||||
));
|
||||
|
||||
//
|
||||
|
||||
@@ -35,6 +35,7 @@ Dict::Add('FR FR', 'French', 'Français', array(
|
||||
'Attachment:Max_Ko' => '(Taille de fichier max.: %1$s Kb)',
|
||||
'Attachments:NoAttachment' => 'Aucune pièce jointe.',
|
||||
'Attachments:PreviewNotAvailable' => 'Pas d\'aperçu pour ce type de pièce jointe.',
|
||||
'Attachments:Error:FileTooLarge' => 'Le fichier est trop gros pour être chargé. %1$s',
|
||||
));
|
||||
|
||||
//
|
||||
|
||||
@@ -54,16 +54,42 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
|
||||
}
|
||||
}
|
||||
|
||||
protected function GetMaxUpload()
|
||||
/**
|
||||
* Returns the value of "upload_max_filesize" in bytes if upload allowed, false otherwise.
|
||||
*
|
||||
* @since 2.6.1
|
||||
*
|
||||
* @return number|boolean
|
||||
*/
|
||||
public static function GetMaxUploadSize()
|
||||
{
|
||||
$iMaxUpload = ini_get('upload_max_filesize');
|
||||
$sMaxUpload = ini_get('upload_max_filesize');
|
||||
if (!$sMaxUpload)
|
||||
{
|
||||
$result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = utils::ConvertToBytes($sMaxUpload);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the max. file upload size allowed as a dictionary entry
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function GetMaxUpload()
|
||||
{
|
||||
$iMaxUpload = static::GetMaxUploadSize();
|
||||
if (!$iMaxUpload)
|
||||
{
|
||||
$sRet = Dict::S('Attachments:UploadNotAllowedOnThisSystem');
|
||||
}
|
||||
else
|
||||
{
|
||||
$iMaxUpload = utils::ConvertToBytes($iMaxUpload);
|
||||
if ($iMaxUpload > 1024*1024*1024)
|
||||
{
|
||||
$sRet = Dict::Format('Attachment:Max_Go', sprintf('%0.2f', $iMaxUpload/(1024*1024*1024)));
|
||||
@@ -327,13 +353,16 @@ EOF
|
||||
}
|
||||
}
|
||||
|
||||
$oPage->add('</span>');
|
||||
$oPage->add('<div style="clear:both"></div>');
|
||||
$sMaxUpload = $this->GetMaxUpload();
|
||||
$oPage->p(Dict::S('Attachments:AddAttachment').'<input type="file" name="file" id="file"><span style="display:none;" id="attachment_loading"> <img src="../images/indicator.gif"></span> '.$sMaxUpload);
|
||||
$oPage->add('</span>');
|
||||
$oPage->add('<div style="clear:both"></div>');
|
||||
$iMaxUploadInBytes = $this->GetMaxUploadSize();
|
||||
$sMaxUploadLabel = $this->GetMaxUpload();
|
||||
$sFileTooBigLabel = Dict::Format('Attachments:Error:FileTooLarge', $sMaxUploadLabel);
|
||||
$sFileTooBigLabelForJS = addslashes($sFileTooBigLabel);
|
||||
$oPage->p(Dict::S('Attachments:AddAttachment').'<input type="file" name="file" id="file"><span style="display:none;" id="attachment_loading"> <img src="../images/indicator.gif"></span> '.$sMaxUploadLabel);
|
||||
|
||||
$oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.iframe-transport.js');
|
||||
$oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.fileupload.js');
|
||||
$oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.fileupload.js');
|
||||
|
||||
$sDownloadLink = utils::GetAbsoluteUrlAppRoot().ATTACHMENT_DOWNLOAD_URL;
|
||||
$oPage->add_ready_script(
|
||||
@@ -362,6 +391,21 @@ EOF
|
||||
}
|
||||
}
|
||||
},
|
||||
send: function(e, data){
|
||||
// Don't send attachment if size is greater than PHP post_max_size, otherwise it will break the request and all its parameters (\$_REQUEST, \$_POST, ...)
|
||||
// Note: We loop on the files as the data structures is an array but in this case, we only upload 1 file at a time.
|
||||
var iTotalSizeInBytes = 0;
|
||||
for(var i = 0; i < data.files.length; i++)
|
||||
{
|
||||
iTotalSizeInBytes += data.files[i].size;
|
||||
}
|
||||
|
||||
if(iTotalSizeInBytes > $iMaxUploadInBytes)
|
||||
{
|
||||
alert('$sFileTooBigLabelForJS');
|
||||
return false;
|
||||
}
|
||||
},
|
||||
start: function() {
|
||||
$('#attachment_loading').show();
|
||||
},
|
||||
|
||||
@@ -38,6 +38,7 @@ Dict::Add('EN US', 'English', 'English', array(
|
||||
'Portal:Button:Delete' => 'Delete',
|
||||
'Portal:EnvironmentBanner:Title' => 'You are currently in <strong>%1$s</strong> mode',
|
||||
'Portal:EnvironmentBanner:GoToProduction' => 'Go back to PRODUCTION mode',
|
||||
'Error:HTTP:400' => 'Bad request',
|
||||
'Error:HTTP:401' => 'Authentication',
|
||||
'Error:HTTP:404' => 'Page not found',
|
||||
'Error:HTTP:500' => 'Oops! An error has occured.',
|
||||
|
||||
@@ -36,6 +36,7 @@ Dict::Add('FR FR', 'French', 'Français', array(
|
||||
'Portal:Button:Delete' => 'Supprimer',
|
||||
'Portal:EnvironmentBanner:Title' => 'Vous êtes dans le mode <strong>%1$s</strong>',
|
||||
'Portal:EnvironmentBanner:GoToProduction' => 'Retourner au mode PRODUCTION',
|
||||
'Error:HTTP:400' => 'Requête incorrecte',
|
||||
'Error:HTTP:401' => 'Authentification',
|
||||
'Error:HTTP:404' => 'Page non trouvée',
|
||||
'Error:HTTP:500' => 'Oups ! Une erreur est survenue.',
|
||||
|
||||
@@ -1383,7 +1383,7 @@ class ObjectController extends AbstractController
|
||||
break;
|
||||
|
||||
default:
|
||||
$oApp->abort(403);
|
||||
$oApp->abort(403, Dict::S('Error:HTTP:400'));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ use Dict;
|
||||
use InlineImage;
|
||||
use DBObjectSet;
|
||||
use DBObjectSearch;
|
||||
use AttachmentPlugIn;
|
||||
use Combodo\iTop\Renderer\FieldRenderer;
|
||||
use Combodo\iTop\Renderer\RenderingOutput;
|
||||
|
||||
@@ -89,6 +90,10 @@ class BsFileUploadFieldRenderer extends FieldRenderer
|
||||
$oOutput->AddHtml('</div>');
|
||||
|
||||
// JS for file upload
|
||||
$iMaxUploadInBytes = AttachmentPlugIn::GetMaxUploadSize();
|
||||
$sMaxUploadLabel = AttachmentPlugIn::GetMaxUpload();
|
||||
$sFileTooBigLabel = Dict::Format('Attachments:Error:FileTooLarge', $sMaxUploadLabel);
|
||||
$sFileTooBigLabelForJS = addslashes($sFileTooBigLabel);
|
||||
// Note : This is based on itop-attachement/main.attachments.php
|
||||
$oOutput->AddJs(
|
||||
<<<EOF
|
||||
@@ -140,6 +145,21 @@ class BsFileUploadFieldRenderer extends FieldRenderer
|
||||
});
|
||||
}
|
||||
},
|
||||
send: function(e, data){
|
||||
// Don't send attachment if size is greater than PHP post_max_size, otherwise it will break the request and all its parameters (\$_REQUEST, \$_POST, ...)
|
||||
// Note: We loop on the files as the data structures is an array but in this case, we only upload 1 file at a time.
|
||||
var iTotalSizeInBytes = 0;
|
||||
for(var i = 0; i < data.files.length; i++)
|
||||
{
|
||||
iTotalSizeInBytes += data.files[i].size;
|
||||
}
|
||||
|
||||
if(iTotalSizeInBytes > $iMaxUploadInBytes)
|
||||
{
|
||||
alert('$sFileTooBigLabelForJS');
|
||||
return false;
|
||||
}
|
||||
},
|
||||
start: function() {
|
||||
// Scrolling to dropzone so the user can see that attachments are uploaded
|
||||
$(this)[0].scrollIntoView();
|
||||
|
||||
Reference in New Issue
Block a user