SuperNinja
SuperNinja

Reputation: 1606

jQuery-file-upload/PHP - Passing the appended file name

I am using the BlueImp jQuery-file-upload to upload files to server. The upload accounts for files that may have the same name appending (1),(2)...etc. The issue that I am having I am sure results from the following code

$('#albumCover.fileupload').bind('fileuploaddone', function(e,data) {

        //Loop through each uploaded file and return object
        $.each(data.files, function (index, file) {
            var filename = file.name;
            $.ajax({ 
                type: "POST",
                url: "../albumUploader/queries/albumCover.php",
                data: {file: filename}
            });
        });
}

I am posting to albumCover.php whatever filename I am selecting, so if it happens to be a duplicate of an existing file, the DB will have duplicate "image.jpg", while the uploader is correctly uploading the files appending (1),(2) etc.

Is anyone familiar how I pass the filename that the uploader is correctly labeling the uploaded files. I should be sending to albumCover.php, and is the POST type the correct type to be using in this situation.

Upvotes: 1

Views: 2181

Answers (1)

SuperNinja
SuperNinja

Reputation: 1606

Hope this helps someone else. Here is where I found my rescource: https://github.com/blueimp/jQuery-File-Upload/issues/641

   $('#albumCover.fileupload').bind('fileuploaddone', function(e,data) {
    var filename = data.result[0].name;
            $.ajax({ 
                type: "POST",
                url: "../albumUploader/queries/albumCover.php",
                data: {file: filename}
            });
    }

the data.result[0].name returns the amended file name

Upvotes: 1

Related Questions