1.在IndexController.class.php里面写2个方法,shangchuan用来显示页面,upload是上传文件的方法。

<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
public function shangchuan()
{
$this->display();
}
public function upload()
{
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize = 31457280 ;// 设置附件上传大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->autoSub = true;
$upload->subName = array('date','Ymd');
$upload->rootPath = "./Public/";//文件上传保存的根路径,下面的Upload文件夹放在这里面,./Public/Upload
$upload->savePath = './Uploads/'; // 设置附件上传目录,文件上传上来以后放在了这个文件件里面。
$info = $upload->upload();
if(!$info) // 上传错误提示错误信息
{
$this->error($upload->getError());
}
else// 上传成功 获取上传文件信息
{
foreach($info as $file){
echo $file['savepath'].$file['savename'];
}
}
}
}
?>

2.显示页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head> <body>
<form action="__CONTROLLER__/upload" method="post" enctype="multipart/form-data">
<input type="file" name="wenjian" />
<input type="submit" value="提交" /> </form>
</body>
</html>

Thinkphp文件上传的更多相关文章

  1. thinkphp文件上传以及图片处理

    文件上传 上传表单 在ThinkPHP中使用上传功能无需进行特别处理.例如,下面是一个带有附件上传的表单提交: <form action="__URL__/upload" e ...

  2. ThinkPHP文件上传类

    TP框架自带文件上传类使用: 类文件在ThinkPHP/Library/Think/默认在目录下 public function upload(){ $upload = new \Think\Uplo ...

  3. ThinkPHP 文件上传到阿里云OSS上(干货)

    参考:http://www.thinkphp.cn/extend/789.html 1.前往阿里云github下载SDK包:https://github.com/aliyun/aliyun-oss-p ...

  4. 2019-07-30 ThinkPHP文件上传

    文件上传就是获取到待上传文件的临时路径,把它移动到服务器下的相应文件夹中. 文件上传,必须在表单中的form标签中写入:enctype="multipart/form-data" ...

  5. thinkphp 文件上传

    form表单中 enctype="multipart/form-data" public function upload()    {      import('ORG.Net.U ...

  6. THINKPHP源码学习--------文件上传类

    TP图片上传类的理解 在做自己项目上传图片的时候一直都有用到TP的上传图片类,所以要进入源码探索一下. 文件目录:./THinkPHP/Library/Think/Upload.class.php n ...

  7. Thinkphp 验证码、文件上传

    一.验证码 验证码参数 例题:登录时验证下验证码 LoginController.class.php <?php namespace Home\Controller; use Think\Con ...

  8. thinkphp实现文件上传

    文件上传详细讲解 http://www.thinkphp.cn/info/194.html 上传根目录不存在问题解决方法 http://www.thinkphp.cn/topic/10779.html

  9. 2016/05/19 thinkphp 3.2.2 文件上传

    显示效果:  多文件上传.  这里是两个文件一起上传 上传到文件夹的效果: ①aa为调用Home下common文件夹下的function.php  中的rname方法  实现的 ②cc为调用与Home ...

随机推荐

  1. swift学习笔记2——函数、闭包

    之前学习swift时的个人笔记,根据github:the-swift-programming-language-in-chinese学习.总结,将重要的内容提取,加以理解后整理为学习笔记,方便以后查询 ...

  2. php-into 安装时遇到的各种问题,php -m跟phpinfo()显示不一致

    系统环境 阿里云服务器 ubuntu nginx php5.4.23 在Yii2中格式显示用户currency,所以需要intl模块,没啥说的装吧. apt-get install libicu-de ...

  3. 微信调用照相拍照等 js 接口的权限配置 和 照片上传和下载实现

    直接上代码: 1. 前端调试代码: <html> <head> <meta http-equiv="Content-Type" content=&qu ...

  4. 刷新页面时 select值保持不变

    刷新页面时,要使下拉菜单(select).raido保持不变,用ajax是无法实现的.我想只能通过cookies才能实现.刷新前先把select或radio的值保存在cookies中,刷新后再填回去. ...

  5. Spring 02多种注入方式和注解实现DI

    一.Bean作用域 spring容器创建的时候,会将所有配置的bean对象创建出来,默认bean都是单例的.代码通过getBean()方法从容器获取指定的bean实例,容器首先会调用Bean类的无参构 ...

  6. 利用Oracle创建表空间和用户

    本文仅用于学习交流,商业用途请支持正版!转载请注明:http://www.cnblogs.com/mxbs/p/6217152.html 第一步,创建表空间 以SYS/sys账户和SYSDBA身份登录 ...

  7. vs2013 error : cannot open source file "SDKDDKVer.h"

    改: 项目属性--常规--工具集--Visual Studio 2013-WindowsXP(v120_xp)

  8. windows系统下fis3安装教程

    注意:在安装fis3前必须安装node和npm,详情请见官网http://nodejs.org node版本要求 0.8.x,0.10.x, 0.12.x,4.x,6.x,不在此列表中的版本不予支持. ...

  9. MongoDB数据库的CURD的一些基本语句

    from:http://www.data321.com/shujuku/20160514417/addToSetQianMianBuXuYaoJinXing 插入文档: SQL语句: INSERT I ...

  10. [LeetCode] Fraction to Recurring Decimal 分数转循环小数

    Given two integers representing the numerator and denominator of a fraction, return the fraction in ...