1

I'm trying to implement the Blueimp jQuery file uploader and am having a frustrating time making it work in my PHP-based site.

My main problem is with AJAX. What I want to do is after uploading,

  1. it'd redirect to (let's say) abc.php.
  2. after uploading (before redirecting page), I want to save the file name to MySQL database.

I know how to handle database with PHP but don't know where I can't put my PHP codes.

For the first problem I guess I need to change 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});
            }
        });
    });


});

Thanks in million..

Core Xii
  • 6,270
  • 4
  • 31
  • 42
user1515848
  • 43
  • 1
  • 5

1 Answers1

1

To do a redirect you might be better just submitting the form and handling all via PHP, except you lose the progress indicator I guess.

Otherwise, if I have understood you properly, you just use the callback functions to perform a javascript redirect on completion of upload. You just add options to one of the methods such as:

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

    }

});

See this answer about redirects: How to redirect to another webpage in JavaScript/jQuery?

Community
  • 1
  • 1
raymosley
  • 643
  • 5
  • 3