Hi all,
Here’s a small change I made in maxygallery to control file upload size in maxigallery and avoid waiting a long time for a response of the server of that king : " Fatal error: Allowed memory size of 33554432 bytes ..."
In maxigallery.php, here is the code modification after line 357
$successfullUploadCounter=0; //NEW
$successfullUploadFilenames='('; //NEW
for($i=0;$i<$mg->mgconfig['upload_field_count'];$i++) { //for each of the upload fields:
$name=$_FILES['file'.$i]['name'];
//if max number of pics limit has been reached, break
if($mg->mgconfig['max_pic_number']!=0 && $name != "" && ($mg->mgconfig['max_pic_number'] < (($i+1) + $modx->db->getRecordCount($rsx)))){
$upload_error = true;
$manageOuterTplData['messages'] .= $mg->strings['max_pics_reached_some_discarded'];
break;
}
if($name!="") {
$name = $mg->getFilename($name);
if ($_FILES['file'.$i]['error'] ) {// THIS IF BLOCK IS NEW
$upload_error = true;//NEW
$handleMessage = '<p style="color:red">';
switch ($_FILES['file'.$i]['error'] ){
case 1: // UPLOAD_ERR_INI_SIZE
$handleMessage .= "The file ".$name." oversizes the server limit";
break;
case 2: // UPLOAD_ERR_FORM_SIZE
$handleMessage .= 'The file '.$name.' oversizes the html form limit';
break;
case 3: // UPLOAD_ERR_PARTIAL
$handleMessage .= "The upload of the file $name has been interrupted during transfert";
break;
case 4: // UPLOAD_ERR_NO_FILE
$handleMessage .= "The file $name has a null size";
break;
}
$handleMessage .= ' : not uploaded</p>';
}
else { // IF NO ERROR DETECTED : WE SEND THE FILE
move_uploaded_file( $_FILES['file'.$i]['tmp_name'] , $mg->path_to_gal.$name );
chmod($mg->path_to_gal.$name,0666);
$handleMessage = $mg->handleFile($name, $modx->db->getRecordCount($rsx));
}
if ($handleMessage != "") {
$manageOuterTplData['messages'] .= $handleMessage;
$upload_error = true;
}
else{
$successfullUploadCounter++;
$successfullUploadFilenames.=$_FILES['file'.$i]['name'].',';
}
}
}
$successfullUploadFilenames.=')';
// THIS COMMENTED : if(!$upload_error){
$manageOuterTplData['messages'] .= $successfullUploadCounter.' '.$mg->strings['pictures_successfully_uploaded'].' '.$successfullUploadFilenames;
// THIS COMMENTED : }
In addition, you can use a manageuploadtpl including a MAX_FILE_SIZE hidden input to control max upload file size in HTML form :
<div class="uploadcounter">
[+maxigallery.counter+]
</div>
<div class="uploadfile">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="2024000 " />
<input name="[+maxigallery.fieldnames.file+]" type="file" />
</div>
Using this code the user will see without delay (only the time to send files under size limit) a information message which looks like this :
The file 01.jpg oversizes the html form limit : not uploaded
The file 03.jpg oversizes the html form limit : not uploaded
4 Pictures uploaded successfully (02.jpg,04.jpg,05.jpg,06.jpg)
Of course, the code will need to be internationalized and cleaned up a bit but it’s working well. What do you think doze ?