[英]Html Php Ajax image upload
i have a small problem at a multi image upload. 我在上传多张图片时遇到了一个小问题。 If I select multiple photos it works great, but if i upload 3 pictures and and upload another 1, it only takes that last picure. 如果我选择多张照片,效果很好,但是如果我上传3张图片并上传另外1张图片,则只会拍摄最后一张照片。 For example 例如
and after I upload another one 然后我上传另一个
i want that when I select a new picture, the array lenght to be 4, the 3 initial picture and the new one (giving a number example), but i don't know how, can you give me some information/documentation. 我希望当我选择一张新图片时,数组长度为4、3张初始图片和一张新图片(给出一个数字示例),但是我不知道如何,能否给我一些信息/文档。 The Code 编码
<div>
<label for="image">Add Picture</label>
<input type="file" id="upload_file" name="upload_file[]" onchange="preview_image();" multiple/>
</div>
<div class="image_preview" id="image_preview"></div>
<div>
and the javascript 和JavaScript
<script>
$(document).ready(function()
{
$('form').ajaxForm(function()
{
alert("Uploaded SuccessFully");
});
});
function preview_image()
{
var total_file=document.getElementById("upload_file").files.length;
for(var i=0;i<total_file;i++)
{
$('#image_preview').append("<img src='"+URL.createObjectURL(event.target.files[i])+"'>");
}
}
</script>
It is not your code problem. 这不是您的代码问题。 When you browse for file and select file for upload and after click on "OK", this input field remove it's old value. 当您浏览文件并选择要上传的文件,然后单击“确定”后,此输入字段将其旧值删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.