php上传文件

<?php

//文件上传
if(!empty($_FILES)){
echo var_dump($_FILES)."<br>";
echo "文件名称:".$_FILES["myfile"]["name"]."<br>";
echo "文件类型:".$_FILES["myfile"]["type"]."<br>";
switch($_FILES["myfile"]["type"]){
case "text/plant":
case "image/png":
case "image/JPG":
case "image/jpeg":
$copyto = time().$_FILES["myfile"]["name"];
if(move_uploaded_file($_FILES["myfile"]["tmp_name"],$copyto)){
echo "成功上传一个文件";
}else{
echo "文件上传失败";
}
break;
default;
echo "不能上传该文件";
die("上传的文件有安全隐患");
echo "哈哈哈";
}
}

?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html" charset="utf-8"/>
<meta name="author" content="blog.anchen8.net" />

<title>上传文件</title>
</head>

<body>
<form action="UploadFile.php" method="POST" enctype="multipart/form-data">
<input type="file" name="myfile"/>
<input type="submit" value="上传"/>
</form>


</body>
</html>

posted @ 2016-11-16 15:35  PHP_zhang  阅读(126)  评论(0)    收藏  举报