【问题标题】:How to use Blueimp jQuery file uploader with PHP?如何在 PHP 中使用 Blueimp jQuery 文件上传器?
【发布时间】:2012-07-12 01:08:27
【问题描述】:

我正在尝试实现 Blueimp jQuery 文件上传器 并且在我的基于 PHP 的网站上运行它时遇到了令人沮丧的事情。

我的主要问题是 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});
            }
        });
    });


});

百万感谢..

【问题讨论】:

    标签: php javascript jquery ajax blueimp


    【解决方案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?

    【讨论】:

      猜你喜欢
      • 2013-05-09
      • 1970-01-01
      • 1970-01-01
      • 2017-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-26
      相关资源
      最近更新 更多