标签:.com jpg cin pac 选中 lsp 目录 har 图片
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
<?phpnamespace Ceshi\Controller;use Think\Controller;class WenjianController extends Controller{ public function shangchuan(){ $this->show(); } public function wjsc(){ $upload = new \Think\Upload(); // 实例化上传类 造对象 $upload->maxSize = 1024000; // 设置附件上传大小 $upload->rootPath = "./Public/"; //文件存放的根路径 $upload->savePath = "upload/"; //设置当前文件存放的位置 $upload->exts = array(‘jpg‘, ‘gif‘, ‘png‘, ‘jpeg‘); // 设置附件上传类型 $info = $upload->upload(); //上传文件并返回文件信息 if(!$info) { // 上传错误提示错误信息 echo $upload->getError(); }else{ //上传成功,遍历$info, //因为返回成功上传的文件信息数组是二维数组 foreach($info as $file) { echo "上传成功,文件存放在:".$file[‘savepath‘].$file[‘savename‘]; } } } } |
第二步:做显示页面 shangchuan.html
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <h1>文件上传</h1> <!--要使用上传功能 你的表单需要设置 enctype="multipart/form-data"--> <form action="__CONTROLLER__/wjsc" method="post" enctype="multipart/form-data"> <input type="file" name="file"/> <input type="submit" value="上传" /> </form> </body></html> |
看一下效果:

点击选中的文件,并打开

文件已经选中:

点击上传:会显示上传成功,并输出 路径 加 文件名

看一下Public文件下的upload文件是否已上传该文件:

选中的图片已经上传到该目录下了~~~~~
标签:.com jpg cin pac 选中 lsp 目录 har 图片
原文地址:http://www.cnblogs.com/Liangbingbing/p/7147836.html