TP文件上传

Posted navyyouth

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TP文件上传相关的知识,希望对你有一定的参考价值。

一、单文件上传

<form action="__ACTION__" enctype="multipart/form-data" method="post" >
	<input type="text" name="name" />
	<input type="file" name="photo" />
	<input type="submit" value="提交" >
</form>

 

<?php
namespace Home\\Controller;
use Think\\Controller;
class LoginController extends Controller{
	public function login(){
		if(!empty($_POST)){
			
			$upd = new \\Think\\Upload();
			$upd->rootPath = "./Public/";
			$upd->savePath = "./upload/";
			$info = $upd->upload();
			
			
		}else{
			$this->show();
		}
	}
	
}

提交以后文件里多了一个文件夹

 

二、多文件上传

<form action="__ACTION__" enctype="multipart/form-data" method="post" >
	<input type="text" name="name" />
	<input type="file" name="photo" />
	<input type="file" name="photo1" />
	<input type="submit" value="提交" >
</form>

 

<?php
namespace Home\\Controller;
use Think\\Controller;
class LoginController extends Controller{
	public function login(){
		if(!empty($_POST)){
			
			$upd = new \\Think\\Upload();
			$upd->rootPath = "./Public/";
			$upd->savePath = "./upload/";
			$info = $upd->upload();
			var_dump($info);
			
			
		}else{
			$this->show();
		}
	}
	
}

 上传两张图片

 

以上是关于TP文件上传的主要内容,如果未能解决你的问题,请参考以下文章