Home > Backend Development > PHP Tutorial > PHP form submission to upload files

PHP form submission to upload files

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-30 13:30:09
Original
1065 people have browsed it

First create the html file containing the form: upload.html

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>上传文件</title>
</head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
    <input type="file" name="file"/>
    <input type="submit" value="提交">
</form>
</body>
</html>
Copy after login



Then create the server file: upload.php

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>显示文件</title>
</head>
<body>
<?php

//print_r($_FILES);

//获取到临时文件
$file=$_FILES[&#39;file&#39;];
//获取文件名
$fileName=$file[&#39;name&#39;];
//移动文件到当前目录
move_uploaded_file($file[&#39;tmp_name&#39;],$fileName);

//显示文件
echo "<img src=&#39;$fileName&#39;>";
?>
</body>
</html>
Copy after login
clicks submit and the file is displayed:


Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above introduces PHP form submission and uploading files, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template