欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php实现表单提交上传文件功能

程序员文章站 2023-12-09 21:56:27
本文实例为大家分享了php实现表单提交上传文件功能的具体代码,供大家参考,具体内容如下 首先创建含表单的html文件:upload.html

本文实例为大家分享了php实现表单提交上传文件功能的具体代码,供大家参考,具体内容如下

首先创建含表单的html文件: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> 

php实现表单提交上传文件功能

再创建服务端文件:upload.php

<!doctype html> 
<html> 
<head> 
  <meta charset="utf-8"> 
  <title>显示文件</title> 
</head> 
<body> 
<?php 
 
//print_r($_files); 
 
//获取到临时文件 
$file=$_files['file']; 
//获取文件名 
$filename=$file['name']; 
//移动文件到当前目录 
move_uploaded_file($file['tmp_name'],$filename); 
 
//显示文件 
echo "<img src='$filename'>"; 
?> 
</body> 
</html> 

点击提交后呈现出文件:

php实现表单提交上传文件功能

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。