我使用 jquery 插件将文件上传到指定的文件夹。上传已正确完成,我想要的是获取文件的名称及其存储在数据库中的路径。我不知道我有哪个变量使用得到那个。这是我的插件,
$(function () {
// Change this to the location of your server-side upload handler:
var url = 'test_upload_charity.php';
$('#fileupload').fileupload({
url: url,
dataType: 'json',
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<p/>').text(file.name).appendTo('#files');
});
},
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress .progress-bar').css(
'width',
progress + '%'
);
}
}).prop('disabled', !$.support.fileInput)
.parent().addClass($.support.fileInput ? undefined : 'disabled');
});
而我的 test_upload_charity.php 是
<?php
error_reporting(E_ALL | E_STRICT);
include "UploadHandler_charity.php";
$uploadhandlerobj=new UploadHandler_charity();
$filename_uploaded=$uploadhandlerobj->get_file_name();
$file = fopen("test123456.txt","w");
echo fwrite($file,"The file is ".$filename_uploaded);
fclose($file);
?>
UploadHandler_charity.php 是
https://github.com/blueimp/jQuery-File-Upload
在该链接中,它位于服务器文件夹中