PHP文件上传实例

来源:互联网 发布:js 按钮显示隐藏 编辑:程序博客网 时间:2024/05/19 05:01
<!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><?phpif (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>

1 0
原创粉丝点击