360浏览器下实现图片上传及时刷新

HTML代码

<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="0">
<title>原生版实现JS上传图片</title>


</head>
<body>
<center><img src="1.jpg" width="200px" height="200px" /></center>
<br/>
 <input style="display:none;" οnchange="shangchuan();" type="file" id="post_file"/>
<center><button οnclick="post_file.click();">上传图片</button></center>
<script>
 if (window.applicationCache.status == window.applicationCache.UPDATEREADY) { 
window.applicationCache.update(); }


function shangchuan(){
//var dir = document.getElementById("post_file").value;

var fd = new FormData();  //表单对象

fd.append("1","测试");
fd.append("usefile",document.getElementById("post_file").files[0]);
var ajax = new XMLHttpRequest();
ajax.open("POST","test.php");

ajax.onreadystatechange = function(){
if(ajax.readyState == 4 && ajax.status == 200){
//alert(ajax.responseText);
window.location.reload();
}
}

ajax.send(fd);

 
}
</script>
</body>
</html>


PHP 代码

<?php
var_dump($_POST);
if(file_exists("1.jpg")){
unlink("1.jpg");
}
move_uploaded_file($_FILES["usefile"]["tmp_name"],"1.jpg");
//var_dump($_FILES);
?>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值