使用jquery-upload-file在CakePHP中自动加载文件

时间:2013-07-16 08:12:40

标签: jquery file cakephp upload

我已将以下代码集成到CakePHP(版本1.3)中: http://sourceforge.net/projects/cakefileupload/

工作正常,点击上传按钮后我就能成功上传文件到服务器。但是,我希望这些文件在我选择后立即自动上传。

我在jquery.fileupload.js中添加了autoUpload:true选项,并将add函数更改为以下内容:

add: function (e, data) {
                if (data.autoUpload || (data.autoUpload !== false &&
                        $(this).fileupload('option', 'autoUpload'))) {
                    data.process().done(function () {
                        data.submit();
                    });
                }
            },

无论如何,我仍然需要单击上传按钮才能将文件转到服务器。任何想法如何启用自动上传?

谢谢!

1 个答案:

答案 0 :(得分:1)

要在选择文件时启用自动上传,请将autoUpload选项设置为true

初始化$(document).ready(function(){...

中的函数时可以使用此选项

您可以看到js文件app\webroot\jupload\js\jquery.fileupload-ui.js。第一个选项设置为false。说实话。

请参阅以下代码:

(function ($) {
'use strict';

// The UI version extends the basic fileupload widget and adds
// a complete user interface based on the given upload/download
// templates.
$.widget('blueimpUI.fileupload', $.blueimp.fileupload, {

    options: {
        // By default, files added to the widget are uploaded as soon
        // as the user clicks on the start buttons. To enable automatic
        // uploads, set the following option to true:
        autoUpload: true, //<----- HERE IS WHAT YOU NEED TO CHANGE
        ..................
        ..................