我想通过使用'jQuery'图像'uploader'插件和'php'上传多个图像(图像的总大小超过32 MB)。怎么做? 我尝试通过AJAX,但没有发送数据。
<form id="form" action="" method="post" enctype="multipart/form-data" >
<!-- <label for="gallery-type">Gallery Type</label>-->
<!-- <select class="form-group" name="gallery_type" id="gallery-
type" style="width: 100px">-->
<!-- <option value="1">1</option>-->
<!-- <option value="2">2</option>-->
<!-- <option value="3">3</option>-->
<!-- <option value="4">4</option>-->
<!-- </select><br>-->
<input class="form-group" type="file" name="images[]" style="width:
200px" id="input" multiple>
<!-- <br>-->
<input class=" form-group btn btn-default" type="submit"
value="upload" name="upload">
</form>
AJAX:
<script>
$('#input').change(function () {
var form = $('#form');
var formData = new FormData(form);
$.ajax({
url: 'lib/upload.php',
type: 'post',
data: formData,
contentType: false,
processData: false,
cache: false,
success: function (data) {
$('#here').html(data);
}
});
});
并返回表单upload.php
<?php include "../lib/functions.php"; ?>
if(isset($_FILES['images'])){
$images = $_FILES['images'];
$images = correct_files_array($images);
foreach($images as $image){
echo "<form action='' method='post'>
Form
<input type='submit' name='upl' class='submit-form' value='upload this image'>
</form><br>";
}
}else{
echo "is not set";
}
答案 0 :(得分:0)
您只需要从
更改此行var form = $('#form');
到
var form = $('#form')[0];
因为要构造FormData对象,您必须在创建FormData对象时指定该表单元素。