01-12文件上传

上传页面

<!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=utf-8" />
<title>无标题文档</title>
</head>

<body>
<form action="chuli.php" method="post" enctype="multipart/form-data">
<input type="file" name="file"/>
<input type="submit" />
</form>
</body>
</html>

效果图:

上传处理页面:

<?php
if($_FILES["file"]["error"])
{echo $_FILES["file"]["error"];
}

else
{
if(($_FILES["file"]["type"]=="image/jpeg" || $_FILES["file"]["type"]=="image/png") && $_FILES["file"]["size"]<1024000)
{
$filename="./file/".date("YmdHis").$_FILES["file"]["name"];
$filename=iconv("UTF-8","gb2312",$filename);


if( file_exists($filename))
{
echo"文件已经存在";
}
else
{ move_uploaded_file($_FILES["file"]["tmp_name"],$filename);
}
}


else
{
echo"文件类型不正确";
}
}

效果图:

1.提交时

2.提交后

原文地址:https://www.cnblogs.com/F4natasy/p/6277294.html