<!DOCTYPE html>
<html>
<head>
<title>上传文件实例</title>
</head>
<body>
<form name="formal" method="post" action="" enctype="multipart/form-data">
上传头像:<input type="file" name="file" id="file" />
<input type="submit" name="upload" id="button" value="提交"/>
</form>
<?php
if (isset($_POST["upload"])) { #单击按钮确认上传文件
if (($_FILES ["file"] ["type"] =="image/gif")|| ($_FILES ["file"] ["type"] =="image/jpeg")||
($_FILES ["file"] ["type"] =="image/png")) {
if ($_FILES ["file"] ["error"]>0) {
echo "Return Code:".$_FILES["file"] ["error"]."</br>";
}
else{
echo "<table width=100%><tr><td>";
echo "文件名称: ".$_FILES["file"] ["name"]."</br>";
echo "文件类型: ".$_FILES["file"] ["type"]."</br>";
echo "文件大小: ".($_FILES["file"] ["size"]/1024)."Kb</br>";
echo "文件临时副本名称: ".$_FILES["file"] ["tmp_name"]."</br>";
if (file_exists("uploadfile/".$_FILES["file"] ["name"])) {
echo $_FILES["file"]["name"]." already exists.";
}
else{
move_uploaded_file($_FILES["file"]["tmp_name"], "uploadfile/".$_FILES["file"] ["name"]);
echo "文件存储在: "."uploadfile/".$_FILES["file"] ["name"];
}
echo "</td><td></td>";
echo "<tr><td colspan=\"2\"><img src =\""."uploadfile/".$_FILES["file"] ["name"]."\"width=150>";
echo "</td></tr></table>";
}
}
else{
echo "上传文件不存在";
}
}
?>
</body>
</html>
PHP文件上传实例
最新推荐文章于 2023-01-30 17:20:07 发布