文件上传2

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>roo.boo</title>
</head>
<body>
<form action="sow.php" method="post"  enctype="multipart/form-data">
<label for="file">文件名: </label>
<input type="file" name="file" id="file">
<input type="submit" name="sub">
</form>
<?php 
if (isset($_FILES['file'])) {
//允许上传图片的后缀名;
$allowedExt = array("gif","jpeg","png","jpg");
$temp = explode(".", $_FILES['file']['name']);
$exten = end($temp);//获取图片后缀;
        if(($_FILES['file']['type'] == "image/jpg")
   ||($_FILES['file']['type'] == "image/jpeg")
||($_FILES['file']['type'] == "image/pjpeg")
||($_FILES['file']['type'] == "image/png")
||($_FILES['file']['type'] == "image/x-png")
||($_FILES['file']['type'] == "image/gif")
   &&($_FILES['file']['size']<204800)
       
  &&in_array($exten, $allowedExt)
  ){
  if($_FILES['file']['error']>0){
  echo "文件上传失原因".$_FILES['file']['error']."<br>";
  }else {
  echo "文件的名字是:".$_FILES['file']['name']."<br>";
  echo "文件的大小是:".($_FILES['file']['size']/1024)."kb<br>";
  echo "文件的储存位置是:".$_FILES['file']['tmp_name']."<br>";
  echo "文件的类型是:".$_FILES['file']['type']."<br>";
  if(file_exists("D:/www/www/study/".$_FILES['file']['name'])){
  echo "文件已经存在"."D:/www/www/study/".$_FILES['file']['name'];
  }else{
  move_uploaded_file($_FILES['file']['tmp_name'],"D:www/www/study/".$_FILES['file']['name'] );
  echo "文件已经存储在位置"."D:/www/www/study".$_FILES['file']['name'];
  }
  
  }
 
}else {
echo "非法文件格式";
}
}


?>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值