Changeset 6625


Ignore:
Timestamp:
06/29/10 20:42:11 (10 years ago)
Author:
plg
Message:

merge r6624 from branch 2.1 to trunk

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)

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions_upload.inc.php

    r6622 r6625  
    300300  return in_array(strtolower($extension), array('jpg', 'jpeg', 'png')); 
    301301} 
     302 
     303function file_upload_error_message($error_code) 
     304{ 
     305  switch ($error_code) { 
     306    case UPLOAD_ERR_INI_SIZE: 
     307      return sprintf( 
     308        l10n('The uploaded file exceeds the upload_max_filesize directive in php.ini: %sB'), 
     309        get_ini_size('upload_max_filesize', false) 
     310        ); 
     311    case UPLOAD_ERR_FORM_SIZE: 
     312      return l10n('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'); 
     313    case UPLOAD_ERR_PARTIAL: 
     314      return l10n('The uploaded file was only partially uploaded'); 
     315    case UPLOAD_ERR_NO_FILE: 
     316      return l10n('No file was uploaded'); 
     317    case UPLOAD_ERR_NO_TMP_DIR: 
     318      return l10n('Missing a temporary folder'); 
     319    case UPLOAD_ERR_CANT_WRITE: 
     320      return l10n('Failed to write file to disk'); 
     321    case UPLOAD_ERR_EXTENSION: 
     322      return l10n('File upload stopped by extension'); 
     323    default: 
     324      return l10n('Unknown upload error'); 
     325  } 
     326} 
     327 
     328function get_ini_size($ini_key, $in_bytes=true) 
     329{ 
     330  $size = ini_get($ini_key); 
     331 
     332  if ($in_bytes) 
     333  { 
     334    $size = convert_shortand_notation_to_bytes($size); 
     335  } 
     336   
     337  return $size; 
     338} 
     339 
     340function convert_shortand_notation_to_bytes($value) 
     341{ 
     342  $suffix = substr($value, -1); 
     343  $multiply_by = null; 
     344   
     345  if ('K' == $suffix) 
     346  { 
     347    $multiply_by = 1024; 
     348  } 
     349  else if ('M' == $suffix) 
     350  { 
     351    $multiply_by = 1024*1024; 
     352  } 
     353  else if ('G' == $suffix) 
     354  { 
     355    $multiply_by = 1024*1024*1024; 
     356  } 
     357   
     358  if (isset($multiply_by)) 
     359  { 
     360    $value = substr($value, 0, -1); 
     361    $value*= $multiply_by; 
     362  } 
     363 
     364  return $value; 
     365} 
     366 
     367function add_upload_error($upload_id, $error_message) 
     368{ 
     369  if (!isset($_SESSION['uploads_error'])) 
     370  { 
     371    $_SESSION['uploads_error'] = array(); 
     372  } 
     373  if (!isset($_SESSION['uploads_error'][$upload_id])) 
     374  { 
     375    $_SESSION['uploads_error'][$upload_id] = array(); 
     376  } 
     377 
     378  array_push($_SESSION['uploads_error'][$upload_id], $error_message); 
     379} 
    302380?> 
  • trunk/admin/include/uploadify/uploadify.php

    r6054 r6625  
    1212 
    1313ob_start(); 
     14echo '$_FILES'."\n"; 
    1415print_r($_FILES); 
     16echo '$_POST'."\n"; 
    1517print_r($_POST); 
     18echo '$user'."\n"; 
    1619print_r($user); 
    1720$tmp = ob_get_contents();  
    1821ob_end_clean(); 
    1922// error_log($tmp, 3, "/tmp/php-".date('YmdHis').'-'.sprintf('%020u', rand()).".log"); 
     23 
     24if ($_FILES['Filedata']['error'] !== UPLOAD_ERR_OK) 
     25{ 
     26  $error_message = file_upload_error_message($_FILES['Filedata']['error']); 
     27   
     28  add_upload_error( 
     29    $_POST['upload_id'], 
     30    sprintf( 
     31      l10n('Error on file "%s" : %s'), 
     32      $_FILES['Filedata']['name'], 
     33      $error_message 
     34      ) 
     35    ); 
     36 
     37  echo "File Size Error"; 
     38  exit(); 
     39} 
     40 
     41ob_start(); 
    2042 
    2143$image_id = add_uploaded_file( 
     
    4163  ); 
    4264 
     65$output = ob_get_contents();  
     66ob_end_clean(); 
     67if (!empty($output)) 
     68{ 
     69  add_upload_error($_POST['upload_id'], $output); 
     70} 
     71 
    4372echo "1"; 
    4473?> 
  • trunk/admin/photos_add_direct.php

    r6622 r6625  
    6363// +-----------------------------------------------------------------------+ 
    6464 
    65 if (isset($_POST['submit_upload'])) 
     65if (isset($_GET['processed'])) 
    6666{ 
    6767//   echo '<pre>POST'."\n"; print_r($_POST); echo '</pre>'; 
     
    6969//   echo '<pre>SESSION'."\n"; print_r($_SESSION); echo '</pre>'; 
    7070//   exit(); 
     71 
     72  // sometimes, you have submitted the form but you have nothing in $_POST 
     73  // and $_FILES. This may happen when you have an HTML upload and you 
     74  // exceeded the post_max_size (but not the upload_max_size) 
     75  if (!isset($_POST['submit_upload'])) 
     76  { 
     77    array_push( 
     78      $page['errors'], 
     79      sprintf( 
     80        l10n('The uploaded files exceed the post_max_size directive in php.ini: %sB'), 
     81        ini_get('post_max_size') 
     82        ) 
     83      ); 
     84  } 
    7185   
    7286  $category_id = null; 
    73   if ('existing' == $_POST['category_type']) 
     87  if (!isset($_POST['category_type'])) 
     88  { 
     89    // nothing to do, we certainly have the post_max_size issue 
     90  } 
     91  elseif ('existing' == $_POST['category_type']) 
    7492  { 
    7593    $category_id = $_POST['category']; 
     
    194212      } 
    195213    } 
     214    else 
     215    { 
     216      $error_message = file_upload_error_message($error); 
     217       
     218      array_push( 
     219        $page['errors'], 
     220        sprintf( 
     221          l10n('Error on file "%s" : %s'), 
     222          $_FILES['image_upload']['name'][$idx], 
     223          $error_message 
     224          ) 
     225        ); 
     226    } 
    196227  } 
    197228   
     
    205236  { 
    206237    // we're on a multiple upload, with uploadify and so on 
    207     $image_ids = $_SESSION['uploads'][ $_POST['upload_id'] ]; 
    208  
    209     associate_images_to_categories( 
    210       $image_ids, 
    211       array($category_id) 
    212       ); 
    213  
    214     $query = ' 
     238    if (isset($_SESSION['uploads_error'][ $_POST['upload_id'] ])) 
     239    { 
     240      foreach ($_SESSION['uploads_error'][ $_POST['upload_id'] ] as $error) 
     241      { 
     242        array_push($page['errors'], $error); 
     243      } 
     244    } 
     245 
     246    if (isset($_SESSION['uploads'][ $_POST['upload_id'] ])) 
     247    { 
     248      $image_ids = $_SESSION['uploads'][ $_POST['upload_id'] ]; 
     249 
     250      associate_images_to_categories( 
     251        $image_ids, 
     252        array($category_id) 
     253        ); 
     254 
     255      $query = ' 
    215256UPDATE '.IMAGES_TABLE.' 
    216257  SET level = '.$_POST['level'].' 
    217258  WHERE id IN ('.implode(', ', $image_ids).') 
    218259;'; 
    219     pwg_query($query); 
     260      pwg_query($query); 
    220261     
    221     invalidate_user_cache(); 
     262      invalidate_user_cache(); 
     263    } 
    222264  } 
    223265   
     
    326368      'F_ADD_ACTION'=> PHOTOS_ADD_BASE_URL, 
    327369      'uploadify_path' => $uploadify_path, 
     370      'upload_max_filesize' => min( 
     371        get_ini_size('upload_max_filesize'), 
     372        get_ini_size('post_max_size') 
     373        ), 
    328374    ) 
    329375  ); 
     
    346392    array( 
    347393      'upload_mode' => $upload_mode, 
     394      'form_action' => PHOTOS_ADD_BASE_URL.'&amp;upload_mode='.$upload_mode.'&amp;processed=1', 
    348395      'switch_url' => PHOTOS_ADD_BASE_URL.'&amp;upload_mode='.$upload_switch, 
    349396      'upload_id' => md5(rand()), 
    350397      'session_id' => session_id(), 
    351398      'pwg_token' => get_pwg_token(), 
     399      'another_upload_link' => PHOTOS_ADD_BASE_URL.'&amp;upload_mode='.$upload_mode, 
    352400    ) 
    353401  ); 
     
    465513} 
    466514 
     515if (get_ini_size('upload_max_filesize') > get_ini_size('post_max_size')) 
     516{ 
     517  array_push( 
     518    $setup_warnings, 
     519    sprintf( 
     520      l10n('In your php.ini file, the upload_max_filesize (%sB) is bigger than post_max_size (%sB), you should change this setting'), 
     521      get_ini_size('upload_max_filesize', false), 
     522      get_ini_size('post_max_size', false) 
     523      ) 
     524    ); 
     525} 
     526 
    467527$template->assign( 
    468528    array( 
  • trunk/admin/themes/default/template/photos_add_direct.tpl

    r6622 r6625  
    5050  } 
    5151 
     52  function humanReadableFileSize(bytes) { 
     53    var byteSize = Math.round(bytes / 1024 * 100) * .01; 
     54    var suffix = 'KB'; 
     55 
     56    if (byteSize > 1000) { 
     57      byteSize = Math.round(byteSize *.001 * 100) * .01; 
     58      suffix = 'MB'; 
     59    } 
     60 
     61    var sizeParts = byteSize.toString().split('.'); 
     62    if (sizeParts.length > 1) { 
     63      byteSize = sizeParts[0] + '.' + sizeParts[1].substr(0,2); 
     64    } 
     65    else { 
     66      byteSize = sizeParts[0]; 
     67    } 
     68 
     69    return byteSize+suffix; 
     70  } 
     71 
    5272  if ($("select[name=category] option").length == 0) { 
    5373    $('input[name=category_type][value=existing]').attr('disabled', true); 
     
    91111var pwg_token = '{$pwg_token}'; 
    92112var buttonText = 'Browse'; 
     113var sizeLimit = {$upload_max_filesize}; 
    93114 
    94115{literal} 
     
    109130    'fileDesc'       : 'Photo files (*.jpg,*.jpeg,*.png)', 
    110131    'fileExt'        : '*.jpg;*.JPG;*.jpeg;*.JPEG;*.png;*.PNG', 
     132    'sizeLimit'      : sizeLimit, 
    111133    'onAllComplete'  : function(event, data) { 
    112134      if (data.errors) { 
     
    119141    onError: function (event, queueID ,fileObj, errorObj) { 
    120142      var msg; 
    121       if (errorObj.status == 404) { 
    122         alert('Could not find upload script.'); 
    123         msg = 'Could not find upload script.'; 
    124       } 
    125       else if (errorObj.type === "HTTP") { 
    126         msg = errorObj.type+": "+errorObj.status; 
     143 
     144      if (errorObj.type === "HTTP") { 
     145        if (errorObj.info === 404) { 
     146          alert('Could not find upload script.'); 
     147          msg = 'Could not find upload script.'; 
     148        } 
     149        else { 
     150          msg = errorObj.type+": "+errorObj.info; 
     151        } 
    127152      } 
    128153      else if (errorObj.type ==="File Size") { 
    129         msg = fileObj.name+'<br>'+errorObj.type+' Limit: '+Math.round(errorObj.sizeLimit/1024)+'KB'; 
     154        msg = "File too big"; 
     155        msg = msg + '<br>'+fileObj.name+': '+humanReadableFileSize(fileObj.size); 
     156        msg = msg + '<br>Limit: '+humanReadableFileSize(sizeLimit); 
    130157      } 
    131158      else { 
    132         msg = errorObj.type+": "+errorObj.text; 
     159        msg = errorObj.type+": "+errorObj.info; 
    133160      } 
    134161 
     
    240267  <p id="batchLink"><a href="{$batch_link}">{$batch_label}</a></p> 
    241268</fieldset> 
    242 <p><a href="">{'Add another set of photos'|@translate}</a></p> 
     269<p><a href="{$another_upload_link}">{'Add another set of photos'|@translate}</a></p> 
    243270{else} 
    244271 
     
    251278</div> 
    252279 
    253 <form id="uploadForm" enctype="multipart/form-data" method="post" action="{$F_ACTION}" class="properties"> 
     280<form id="uploadForm" enctype="multipart/form-data" method="post" action="{$form_action}" class="properties"> 
    254281    <fieldset> 
    255282      <legend>{'Drop into category'|@translate}</legend> 
  • trunk/language/en_UK/admin.lang.php

    r6419 r6625  
    758758$lang['This theme was not designed to be directly activated'] = 'This theme was not designed to be directly activated'; 
    759759$lang['Pending Comments'] = 'Pending Comments'; 
     760$lang['In your php.ini file, the upload_max_filesize (%sB) is bigger than post_max_size (%sB), you should change this setting'] = 'In your php.ini file, the upload_max_filesize (%sB) is bigger than post_max_size (%sB), you should change this setting'; 
     761$lang['Exif extension not available, admin should disable exif use'] = 'Exif extension not available, admin should disable exif use'; 
     762$lang['The uploaded file exceeds the upload_max_filesize directive in php.ini: %sB'] = 'The uploaded file exceeds the upload_max_filesize directive in php.ini: %sB'; 
     763$lang['The uploaded files exceed the post_max_size directive in php.ini: %sB'] = 'The uploaded files exceed the post_max_size directive in php.ini: %sB'; 
     764$lang['The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'] = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'; 
     765$lang['The uploaded file was only partially uploaded'] = 'The uploaded file was only partially uploaded'; 
     766$lang['No file was uploaded'] = 'No file was uploaded'; 
     767$lang['Missing a temporary folder'] = 'Missing a temporary folder'; 
     768$lang['Failed to write file to disk'] = 'Failed to write file to disk'; 
     769$lang['File upload stopped by extension'] = 'File upload stopped by extension'; 
     770$lang['Unknown upload error'] = 'Unknown upload error'; 
     771$lang['Error on file "%s" : %s'] = 'Error on file "%s" : %s'; 
    760772?> 
  • trunk/language/fr_FR/admin.lang.php

    r6421 r6625  
    763763$lang['This theme was not designed to be directly activated'] = 'Ce thème n\'est pas conçu pour être activé directement'; 
    764764$lang['Pending Comments'] = 'Commentaires en attente'; 
     765$lang['In your php.ini file, the upload_max_filesize (%sB) is bigger than post_max_size (%sB), you should change this setting'] = 'Dans votre fichier php.ini, la variable upload_max_filesize (%sB) est plus grande que post_max_size (%sB), vous devriez modifier ce paramétrage'; 
     766$lang['Exif extension not available, admin should disable exif use'] = 'L\'extension Exif n\'est pas disponible, un administrateur devrait désactiver l\'utilisation des métadonnées Exif'; 
     767$lang['The uploaded file exceeds the upload_max_filesize directive in php.ini: %sB'] = 'Le poids du fichier transféré dépasse la valeur de upload_max_filesize définie dans votre fichier php.ini: %sB'; 
     768$lang['The uploaded files exceed the post_max_size directive in php.ini: %sB'] = 'Le poids total des fichiers transférés dépasse la valeur de post_max_size dans votre fichier php.ini: %sB'; 
     769$lang['The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'] = 'Le poids du fichier transféré dépasse la valeur de MAX_FILE_SIZE définie dans le formulaire HTML'; 
     770$lang['The uploaded file was only partially uploaded'] = 'Le fichier n\é até que partiellement transféré'; 
     771$lang['No file was uploaded'] = 'Aucun fichier n\'a été transféré'; 
     772$lang['Missing a temporary folder'] = 'Impossible de trouver le répertoire temporaire'; 
     773$lang['Failed to write file to disk'] = 'Échec à l\'écriture du fichier sur le serveur'; 
     774$lang['File upload stopped by extension'] = 'Le transfert du fichier a été arrêté par une extension'; 
     775$lang['Unknown upload error'] = 'Erreur inconnue survenue lors du transfert'; 
     776$lang['Error on file "%s" : %s'] = 'Erreur sur le fichier "%s" : %s'; 
    765777?> 
Note: See TracChangeset for help on using the changeset viewer.