我做的图片上传到Ajax和发送与形式到PHP。但我有搜索到很多来源,但仍然没有idea.can任何人帮我完成的代码?与图像Ajax和PHP上传表单
<form name="registerform" id="data">
<div id="formleft">
<input type="email" name="email" placeholder="Email Address"><br>
<input type="file" id="pic" name="profile_pic" class="image_input" />
<input type="button" name="register" value="Sign Up" onclick="re2()" /><br>
</div>
</form>
function re2()
{
var image=document.getElementById("pic").src;
var re_email1=$("[name=register_email]").val();
$.ajax({
type : "get",
url : "add.php",
data : "type=regis2&image="+image+"&re_email="+email,
success : function(data){
alert(data);
*/ how i get the image file from form and pass the file to here and send ?? */
}
});
}
<?php
if ($_GET['type'] == "regis2")
{
$image=$_GET['image'];
$email=$_GET['re_email'];
$target_Path = 'image/';
$target_Path = $target_Path.basename($_FILES['image']['name']);
move_uploaded_file($_FILES["image"]["tmp_name"] , $target_Path);
}
?>
}
我该如何传递图像使用ajax.becuase我有搜索谷歌,但仍然不知道。任何人都可以为我完成代码? 确实需要很多帮助
我想你所想的文件传递给PHP直接,你可以通过AJAX也以同样的方式的方式完整实现AJAX文件上传。但事实并非如此,为了通过AJAX传递文件,你需要有一个FormData对象。这[后](http://stackoverflow.com/questions/10899384/uploading-both-data-and-files-in-one-form-using-ajax)会帮助你。 –
你能给我完整的代码吗? ,因为我新手这里只是进入ajax – user3149572