当前位置: 移动技术网 > IT编程>开发语言>PHP > php实现表单提交上传文件功能

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

2019年05月30日  | 移动技术网IT编程  | 我要评论

本文实例为大家分享了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> 


再创建服务端文件: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> 

点击提交后呈现出文件:

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网