2012-07-12 64 views
1

我试图实现Blueimp jQuery文件上传 ,并有一个令人沮丧的时间使它在我的基于PHP的网站中工作。如何在PHP中使用Blueimp jQuery文件上传器?

我的主要问题是使用AJAX。 我想要做的就是上传后,

  1. 它会重定向到(比方说)abc.php
  2. 上传后(重定向页面之前),我想将文件名保存到MySQL数据库。

我知道如何用PHP处理数据库,但不知道我不能放置我的PHP代码。

因为我想我需要改变main.js

$(function() { 

'use strict'; 

// Initialize the jQuery File Upload widget: 
$('#fileupload').fileupload(); 

// Enable iframe cross-domain access via redirect option: 
$('#fileupload').fileupload(
    'option', 
    'redirect', 
    window.location.href.replace(
     /\/[^\/]*$/, 
     '/cors/result.html?%s' 
    ) 
);  
    // Load existing files: 
    $('#fileupload').each(function() { 
     var that = this; 
     $.getJSON(this.action, function (result) { 
      if (result && result.length) { 
       $(that).fileupload('option', 'done') 
        .call(that, null, {result: result}); 
      } 
     }); 
    }); 


}); 

感谢百万的第一个问题..

回答

1

要进行重定向,你可能会更好只是提交表单,并通过PHP处理所有,除我猜你失去了进度指示器。否则,如果我已经正确理解了你,你只需使用回调函数在上传完成时执行JavaScript重定向。你只需要添加选项的方法,如一个:

$('#fileupload').fileupload({ 
done: function (e, data) { 
    // Do redirect using either href or replace method 

    // similar behavior as clicking on a link 
    window.location.href = "/abc.php"; 

    } 

}); 

看到这个答案对重定向:How to redirect to another webpage in JavaScript/jQuery?

相关问题