php+ajax上传图片

来源:互联网 发布:阿里云待遇 编辑:程序博客网 时间:2024/04/28 01:17

用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

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