zoukankan      html  css  js  c++  java
  • Thinkphp 上传图片

    <?php
    // 本类由系统自动生成,仅供测试用途
    class ListAction extends Action {
    	    public function index(){
        //$name = 'sunzhiayn';
        //$this->assign('name',$name);
        //$this->assign('admin',$res);	
        $this->display();
      }
      public function article(){ 
      	$cons = M ('Content');   //内容表
      	$cons1 = M('Admin');    //会员表
        $res = $cons->order('id')->select();
       // echo $res[0]['title'];
        $arr = array();
        for($i=0;$i<count($res);$i++){  
           $where['q_id'] = $res[$i]['q_id'];
           //echo $where['q_id'];
           //find查出的是一个一维数组
           $a[$i] = $cons1->where($where)->find();
           if($a[$i]){
             $res[$i]['username'] = $a[$i]['username'];
           }else{
           	$res[$i]['username'] = '未知';
           }
           
        }
      	//var_dump($a);
      	$this->assign('content',$res);
        $this->display();
      }
      
      public function up(){   
          echo '执行修改';
        }
    /* @sunzhiyan
     * 包含多选的删除方法
      */  
      public function del(){
      	echo '执行删除';
      	$cons = M ('Content');   //内容表
    
      	if($_GET['action'] == del ){
           // print_r($_POST['checkbox']);
            $page = $_POST['checkbox'];
            $where = 'id in('.implode(',',$page).')';
          // $page = implode(",",$_POST['checkbox']);     
            //$cons->where($where)->delete();
      	}elseif($_GET['id']){
    	  	$where['id'] = $_GET['id']; 	
      	       }
      		$bool = $cons->where($where)->delete();
    	  	if($bool){
    	         $this->success('删除成功,正在跳转....', '__URL__/article');  		
    	  	}else{
    	  	     $this->error('新增失败,请重新执行','__URL__/article');  		
    	  	}
    	  	//多选删除;  */
      	$this->display();   
      }
      
      public function add() {         
      	
      	echo '这里是添加文章';
      	$clean = array();
    	$clean['title'] =  $_POST['tilte'];
    	$clean['type'] =  $_POST['select'];
    	$clean['contents'] =  $_POST['contents'];
    	$clean['img'] = $_FILES['photo1']['name'];
    	$clean['reg'] = date("Y-m-d",time());
        $con = M('Content'); // 实例化User对象
        if($_GET['action'] == add){
           if($clean['img']){	     	
              //调用文件上传
              $info = $this->upimg();
           	   //print_r($info);   	
             }
             //接收文件上传后的编码文件,存入数据库中
            $clean['img'] =  $info[0]['savename'];
        	$res = $con->add($clean);  
    	    	if($res){
    	    	// $this->success('添加成功,跳转中....','__URL__/article');
    	    	} else{
    	    	 //$this->error('添加失败,跳转中....','__URL__/add');
    	    	}
        }
    	
      	$this->display();
      }
      
    
      public function upimg(){
         import('ORG.Net.UploadFile');
    			$upload = new UploadFile();// 实例化上传类
    			$upload->maxSize  = 3145728 ;// 设置附件上传大小
    			$upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
    			$upload->savePath =  './Public/Uploads/';// 设置附件上传目录
    			if(!$upload->upload()) {// 上传错误提示错误信息
    				$this->error($upload->getErrorMsg());
    			}else{// 上传成功 获取上传文件信息
    				
    			   $info =  $upload->getUploadFileInfo();
    			   //print_r($info);
    			}
    			        	
         return $info;
      }
      
    
    }
    
  • 相关阅读:
    HDU-1215 七夕节 数论 唯一分解定理 求约数之和
    LightOJ-1259 Goldbach`s Conjecture 数论 素数筛
    [前端-动态数据可视化]横向柱状图的动态数据可视化
    CodeForces-722C Destroying Array 并查集 离线操作
    CodeForces-920E Connected Components? 广度搜索 双向链表 判断联通 大量重复节点的删除
    CodeForces-1007A Reorder the Array 贪心 田忌赛马
    POJ-3692 Kindergarten 二分图 最大团
    个人开发者做一款Android App需要知道的事情
    android各种组件的监听器
    留言处插入xss不弹框
  • 原文地址:https://www.cnblogs.com/sunxun/p/4370121.html
Copyright © 2011-2022 走看看