php+html(form+iframe)实现文件的异步上传

html中的代码: 

<form action="file.php" method="post"enctype="multipart/form-data" target="demo">
		<label for="file">
		</label><input type="file" name="file" id="file"/> <br />
		<input type="submit" name="name" value="上传" />
</form>
<iframe height="300px" width="300px" frameborder=0 marginheight="10px" marginwidth="10px" name="demo"> 
</iframe>

file.php中的代码:

//请求接收
if(isset($_FILES["file"])){
	$F=$_FILES["file"];
	$File->upfile($path,$F);
}
//文件保存主函数
class File{
	public function upfile($path,$file){	
		$type=$file["type"];
		$size=$file["size"];
		$name=$file["name"];
		$tmp_name=$file["tmp_name"];
		if (($type=="image/gif"||$type=="image/jpeg"||$type=="image/pjpeg")&&($size<200000)){
		  	if ($file["error"] > 0){
			    echo "<b>返回代码:".$file["error"]."<b><br />";
			}else{
                            //判断文件是否已经存在
			    if (file_exists($path.$name)){
						echo $name."<b>经存在<b>";
					}else{
                                     //保存在服务器指的路径$path.$name
						move_uploaded_file($tmp_name,$path.$name);
					}
		    }
		 }
		else{
		  echo "<b>无效的文件</b>";
		}
	}
}

 

转载于:https://my.oschina.net/hibony/blog/712937

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值