我正在使用文件上传器 jquery 插件以便在我的网站上上传 ajax 文件。但是,我只是无法弄清楚出了什么问题以及为什么它不起作用。
插件: http: //fineuploader.com/index.html
我的代码:
我直接从他们的演示中获取了代码:
$(document).ready(function() {
$fub = $('#fine-uploader-basic');
$messages = $('#messages');
var uploader = new qq.FileUploaderBasic({
button: $fub[0],
action: 'http://localhost/script/file_upload/upload_test',
debug: true,
allowedExtensions: ['jpeg', 'jpg', 'gif', 'png'],
sizeLimit: 204800, // 200 kB = 200 * 1024 bytes
onSubmit: function(id, fileName) {
$messages.append('<div id="file-' + id + '" class="alert" style="margin: 20px 0 0"></div>');
},
onUpload: function(id, fileName) {
$('#file-' + id).addClass('alert-info')
.html('<img src="client/loading.gif" alt="Initializing. Please hold."> ' +
'Initializing ' +
'“' + fileName + '”');
},
onProgress: function(id, fileName, loaded, total) {
if (loaded < total) {
progress = Math.round(loaded / total * 100) + '% of ' + Math.round(total / 1024) + ' kB';
$('#file-' + id).removeClass('alert-info')
.html('<img src="client/loading.gif" alt="In progress. Please hold."> ' +
'Uploading ' +
'“' + fileName + '” ' +
progress);
} else {
$('#file-' + id).addClass('alert-info')
.html('<img src="client/loading.gif" alt="Saving. Please hold."> ' +
'Saving ' +
'“' + fileName + '”');
}
},
onComplete: function(id, fileName, responseJSON) {
if (responseJSON.success) {
$('#file-' + id).removeClass('alert-info')
.addClass('alert-success')
.html('<i class="icon-ok"></i> ' +
'Successfully saved ' +
'“' + fileName + '”' +
'<br><img src="img/success.jpg" alt="' + fileName + '">');
} else {
$('#file-' + id).removeClass('alert-info')
.addClass('alert-error')
.html('<i class="icon-exclamation-sign"></i> ' +
'Error with ' +
'“' + fileName + '”: ' +
responseJSON.error);
}
}
});
});
HTML:
<div id="fine-uploader-basic" class="btn btn-success">
<i class="icon-upload icon-white"></i> Click to upload
</div>
<div id="messages"></div>
PHP:
public function upload_test() {
$upload = move_uploaded_file('./user_files', $_FILES['qqfile']['tmp_name']);
if($upload) {
echo json_encode(array('success' => true));
} else {
echo json_encode(array('success' => false, 'error' => $upload));
}
}
我认为问题出在 PHP 上,但我不知道我做错了什么。在我发疯之前请帮忙。
谢谢你。