现在的位置: 首页 > 综合 > 正文

php+ajax上传图片

2013年11月15日 ⁄ 综合 ⁄ 共 827字 ⁄ 字号 评论关闭
用iframe模拟ajax上传

index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

</head>
<body>
<form id="content" action="upload.php" method="post" target="uploadFrame" enctype="multipart/form-data">
	 <input type="file" name="upload">
	 <input type="submit" value="submit">
	 <iframe name="uploadFrame" style="display:none;"></iframe>
</form>
<div><img src='' id='uploadPic'></div>
<script type="text/javascript">
function showPic(img){
	var imgObj = document.getElementById('uploadPic');
	imgObj.src = img;
}
</script>
</body>
</html>

upload.php

<?php
if(move_uploaded_file($_FILES["upload"]["tmp_name"], "img/a.jpg"))
{
    echo ("<script type=\"text/javascript\">parent.showPic('img/a.jpg')</script>");
}
?>

抱歉!评论已关闭.