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;
      }
      
    
    }
    
  • 相关阅读:
    elementui 修改合计行样式
    C# 导出Excel NPOI 修改指定单元格的样式 或者行样式
    向基于语义模型的操作集成的演变
    在制造业的工业2.0中应用MOM系统
    制造运营管理 (MOM) 的工作流驱动方法
    语义模型在智能工业运营中的作用
    定义运营系统架构
    在离散混合制造环境中应用制造运营模型
    面试官:如果存取IP地址,用什么数据类型比较好 (C#版本)
    使用WtmPlus低代码平台提高生产力
  • 原文地址:https://www.cnblogs.com/sunxun/p/4370121.html
Copyright © 2011-2022 走看看