2

我在这里迷路了。我正在尝试设置由 SWFUpload 处理的简单文件上传。文件选择后没有任何反应。我没有看到正在发送的请求,我的控制台中也没有任何内容。swf 对象是否应该立即调用我的 upload_url 页面?

        var swfu,jobForm;
        var j = jQuery.noConflict();
        j(window).load(function() {
            jobForm = j('.admin-atomic-form form');
            swfu = new SWFUpload({
                upload_url : "URL/upload.php",
                flash_url : "URL/swfupload.swf",
                file_size_limit : "20 MB",
                file_types : "*.doc;*.pdf;*.rtf;*docx;*.jpg;",
                //file_types_description : "All Files",
                file_upload_limit : "1",
                button_placeholder_id : "swfuploader",
                button_image_url : "URL/file-browse.png",
                button_width: 100,
                button_height: 30,
                upload_start_handler : uploadStart,
                upload_success_handler : uploadSuccess
            }); 
            //jobForm.form.submit(function(ev){ev.preventDefault()})
        });

        function uploadStart(){
            //.submit()
            console.log(this,'start');
        };
        function uploadSuccess(){
            //form.submit()
            console.log('success');
        }
4

2 回答 2

0

开始上传文件是一个两步过程:1.您选择一个文件(然后在输入框中填充路径),2.您必须提交表单才能开始实际上传。

我假设您没有执行第 2 步,因为在您的代码中,您已注释掉form.submit()

请取消注释此行://jobForm.form.submit(function(ev){ev.preventDefault()})

然后在您选择文件后,提交表单。

于 2012-08-29T15:42:38.050 回答
0

SWFUploadObj.startUpload();需要被触发,这就是向指定的上传 URL 发起 POST 请求的原因。如果这个方法是由一些默认设置触发的,它肯定不是为我做的。

这是我的一些功能的示例:

// Bound to file_queued_handler : sets a flag that there is a file waiting to upload 
function swfuFileQueued(file){
    resumeQueued = true;
    $j('#browseFile').val(file.name);
}


//Bound to form submit event:
//a successful upload will submit this form again once the success response with the server-moved and renamed filename comes back from the file upload handling script

function swfuFormSubmit(ev){
    if(uploadSuccess){
        return true;
    } else {
        if(resumeQueued == true){
            ev.preventDefault();
            swfuUploadStart(); // see next function
        } else {
            return true;
        }
    }
}

function swfuUploadStart(){
    try {
        swfu.startUpload(); // <-- The actual method that begins the file upload request
    } catch (e) {
    }
    return false;
}

function swfuProgress(){ ...
function swfuError(){ ...
function swfuSuccess(){ 
    //update input element containing filename or id to send with form
    //update a status box with "Success"
    //uploadSuccess = true 
    //form.submit() once more, this time uploadSuccess will tell the function to continue on and actually submit itself

了解 SWFUpload 过程的有用 URL:http ://www.dconstructing.com/2010/07/08/making-swfupload-work

于 2012-08-29T22:38:40.997 回答