【问题标题】:Jquery File Upload blueimp cannot change error message textJquery File Upload blueimp 无法更改错误消息文本
【发布时间】:2017-09-03 10:50:34
【问题描述】:

我正在使用 blueimp 著名的 jquery 文件上传插件在我的服务器上上传文件。我想将错误消息更改为我自己的语言,但我卡住了。

这只是我的内置 UploadHandler.php 文件的错误消息部分(由于限制,我无法共享整个文件,所以我只复制相关部分。)位于 server/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'
    );

.
.
.
.
.
.
.

这是我位于 js/main.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});
        });
    }

});

【问题讨论】:

    标签: php jquery jquery-plugins jquery-file-upload blueimp


    【解决方案1】:

    我希望这可以帮助某人。

    在 jquery_upload/js 中找到 jquery.fileupload-validade.js

    搜索“//错误和信息消息:”(第 71 行附近)。

    手动更改消息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-18
      • 2015-03-06
      • 2017-08-13
      • 2011-12-27
      • 1970-01-01
      • 1970-01-01
      • 2013-05-19
      • 2023-03-09
      相关资源
      最近更新 更多