繁体   English   中英

如何在PHP中使用Blueimp jQuery文件上传器?

[英]How to use Blueimp jQuery file uploader with PHP?

我正在尝试实现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重定向即可。 您只需向以下方法之一添加选项:

$('#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";

    }

});

请参阅有关重定向的以下答案: 如何在JavaScript / jQuery中重定向到另一个网页?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM