0
由於一些奇怪的原因,當我上傳文件時,以下代碼不會打印出任何內容。我認爲HTML5/jQuery會返回一些東西,但是當我打印出我的變量時,我沒有收到任何迴應。如何上傳HTML5文件?
<? print_r($_FILES) ?>
<? print_r($_POST) ?>
<? print_r($_GET) ?>
<? print_r($_REQUEST) ?>
<form enctype="multipart/form-data" action="/upload.php"
method="post" class="putImages">
<input name="media[]" type="file" multiple/>
<input class="button" type="submit" alt="Upload" value="Upload" />
</form>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(function() {
var data = new FormData($('input[name^="media"]'));
jQuery.each($('input[name^="media"]')[0].files, function(i, file) {
data.append(i, file);
});
$(':file').on('change', function() {
$.ajax({
type: 'POST',
data: data,
url: 'http://localhost/upload.php',
cache: false,
contentType: false,
processData: false,
success: function(data){
alert(data);
}
});
});
});
</script>
哦,有可以做這件事庫的數量。使用它們(或者至少查看源代碼)而不是實現自己的解決方案。他們還提供了進度條樣式AJAX上傳 – Yang 2013-02-15 04:12:34
使用此庫https://github.com/blueimp/jQuery-File-Upload ... – AlphaMale 2013-02-15 04:18:41