<html>
<body>
<form action = "upload2.php" method = "post" enctype="multipart/form-data">
<label for="file">Filename:</label> <br><br>
<input type="file" name="file" id="file" > <br><br>
<input type="submit" name="submit" value="上传文件" >
</form>
</body>
</html>
"upload2.php"
<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
{
if ($_FILES["file"]["error"] > 0) //有文件上传导致的错误代码
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>"; //文件的名字
echo "Type: " . $_FILES["file"]["type"] . "<br>";//类型
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br>"; //大小
echo "Stored in: " . $_FILES["file"]["tmp_name"];// 储存在服务器的临时副本名称
if(file_exists("./".$_FILES["file"]["name"]))
{
echo "exist <br>";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],"./".$_FILES["file"]["name"]);
}
}
}
else
{
echo "Invalid file";
}
?>