PHP 文件上传实现

前端上传文件:file_upload.html

<html>
<head>
    <title>文件上传</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<form action="file_upload.php" method="post" enctype="multipart/form-data">
    <label for="file">1. </label>
    <input type="file" name="file" id="file" />
    <hr />
    <label for="submit">2. </label>
    <input type="submit" name="submit" id="submit" value="提交" />
</form>
</body>
</html>

 

后台接收上传文件并显示信息:file_upload.php

<?php

if (empty($_FILES)) {
    echo “文件上传异常<br />”;
} else {
    echo “文件名称: ” . $_FILES["file"]["name"] . “<br />”;
    echo “文件类型: ” . $_FILES["file"]["type"] . “<br />”;
    echo “文件大小: ” . ($_FILES["file"]["size"] / 1024) . ” Kb<br />”;
    echo “临时路径: ” . $_FILES["file"]["tmp_name"];
}

?>

 

posted @ 2017-06-30 10:53  苦瓜糖水  阅读(157)  评论(0编辑  收藏  举报