我正在使用BlueImp jQuery-file-upload将文件上传到服务器。上传帐户可能具有相同名称的文件附加 (1)、(2)...等。我遇到的问题我确定是由以下代码引起的
$('#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}
});
});
}
我正在发布到albumCover.php无论我选择什么文件名,所以如果它恰好是现有文件的副本,数据库将具有重复的"image.jpg",而上传者正在正确上传附加(1),(2)等的文件。
有没有人熟悉我如何传递上传者正确标记上传文件的文件名。我应该发送到专辑封面.php,并且在这种情况下使用的 POST 类型是否正确。
希望这对其他人有所帮助。这是我找到我的资源的地方: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}
});
}
data.result[0].name 返回修改后的文件名