2017-04-07 67 views
1

我使用blueimp的着名jquery文件上傳插件來上傳我的服務器上的文件。我想將錯誤消息更改爲我自己的語言,但我堅持。jquery文件上傳blueimp無法更改錯誤消息文本

這裏只是我內置的UploadHandler.php文件(我無法共享限制的全部文件原因,所以我只是複製相關部分)的錯誤消息部分位於服務器/ php/UploadHandler.php。我已將錯誤文本更改爲我自己的語言,但不受影響。我幾乎閱讀了關於這個插件在stackoverflow上的所有文章,我找不到任何令人滿意的解決方案。等待你的幫助,提前致謝。

class UploadHandler 
{ 

    protected $options; 

    // PHP File Upload error message codes: 
    // http://php.net/manual/en/features.file-upload.errors.php 
    protected $error_messages = array(
     1 => 'The uploaded file exceeds the upload_max_filesize directive in php.ini', 
     2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', 
     3 => 'The uploaded file was only partially uploaded', 
     4 => 'No file was uploaded', 
     6 => 'Missing a temporary folder', 
     7 => 'Failed to write file to disk', 
     8 => 'A PHP extension stopped the file upload', 
     'post_max_size' => 'The uploaded file exceeds the post_max_size directive in php.ini', 
     'max_file_size' => 'File is too big', 
     'min_file_size' => 'File is too small', 
     'accept_file_types' => 'Filetype not allowed', 
     'max_number_of_files' => 'Maximum number of files exceeded', 
     'max_width' => 'Image exceeds maximum width', 
     'min_width' => 'Image requires a minimum width', 
     'max_height' => 'Image exceeds maximum height', 
     'min_height' => 'Image requires a minimum height', 
     'abort' => 'File upload aborted', 
     'image_resize' => 'Failed to resize image' 
    ); 

. 
. 
. 
. 
. 
. 
. 

這裏是我main.js文件位於JS/main.js

$(function() { 
    'use strict'; 

    // Initialize the jQuery File Upload widget: 
    $('#fileupload').fileupload({ 
     // Uncomment the following to send cross-domain cookies: 
     //xhrFields: {withCredentials: true}, 
     url: 'server/php/' 
    }); 

    // Enable iframe cross-domain access via redirect option: 
    $('#fileupload').fileupload(
     'option', 
     'redirect', 
     window.location.href.replace(
      /\/[^\/]*$/, 
      '/cors/result.html?%s' 
     ) 
    ); 

    if (window.location.hostname === 'blueimp.github.io') { 
     // Demo settings: 
     $('#fileupload').fileupload('option', { 
      url: '//jquery-file-upload.appspot.com/', 
      // Enable image resizing, except for Android and Opera, 
      // which actually support image resizing, but fail to 
      // send Blob objects via XHR requests: 
      disableImageResize: /Android(?!.*Chrome)|Opera/ 
       .test(window.navigator.userAgent), 
      maxFileSize: 999000, 
      acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i 
     }); 
     // Upload server status check for browsers with CORS support: 
     if ($.support.cors) { 
      $.ajax({ 
       url: '//jquery-file-upload.appspot.com/', 
       type: 'HEAD' 
      }).fail(function() { 
       $('<div class="alert alert-danger"/>') 
        .text('Upload server currently unavailable - ' + 
          new Date()) 
        .appendTo('#fileupload'); 
      }); 
     } 
    } else { 
     // Load existing files: 
     $('#fileupload').addClass('fileupload-processing'); 
     $.ajax({ 
      // Uncomment the following to send cross-domain cookies: 
      //xhrFields: {withCredentials: true}, 
      url: $('#fileupload').fileupload('option', 'url'), 
      dataType: 'json', 
      context: $('#fileupload')[0] 
     }).always(function() { 
      $(this).removeClass('fileupload-processing'); 
     }).done(function (result) { 
      $(this).fileupload('option', 'done') 
       .call(this, $.Event('done'), {result: result}); 
     }); 
    } 

}); 

回答

0

我希望這可以幫助別人。

找到jquery.fileupload-validade.js內jquery_upload/JS

搜索 「//錯誤和信息消息:」(約71行)。

手動更改消息。

相關問題