. Then create a server file: upload.php."/> . Then create a server file: upload.php.">

Home  >  Article  >  Backend Development  >  How to implement form submission in php

How to implement form submission in php

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-09-29 15:27:422807browse

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>

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>

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!

Statement:
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