How to implement form submission in php

爱喝马黛茶的安东尼
Release: 2023-02-25 16:04:01
Original
2835 people have browsed it

How to implement form submission in php

How to implement form submission in php, the specific steps are as follows:

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

<!DOCTYPE html> 
<html> 
<head> 
  <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

Related recommendations: "php Getting Started Tutorial"

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; alt="How to implement form submission in php" >"; 
?> 
</body> 
</html>
Copy after login

Click submit and the file will be displayed:

How to implement form submission in php

The above is the detailed content of How to implement form submission in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!