• CI 图片上传路径问题的解决


     很久没有用CI了,新公司需要用ci ,图片上传的功能,我都搞半天,伤心

    1. 要看源码,upload.php里do_upload()是上传的主要函数。

    public function do_upload($field = 'userfile')
    	{
            //
            }
    

      默认name = 'userfile',这里要写你自己的name

    2.要测试,不能盲目的,盲目的以程序能否正确执行来判断

    // 图片上传
    			$config ['upload_path'] = 'data/flash';
    			$config ['allowed_types'] = 'gif|jpg|png';
    			$config ['max_size'] = '1024*2';
    			$config ['max_width'] = '1024';
    			$config ['max_height'] = '768';
    			// $config['encrypt_name'] = TRUE;
    			$this->load->library ( 'upload', $config );
    			
    			if (! $this->upload->do_upload ( 'imgUrl' )) {
    				$error = array (
    						'error' => $this->upload->display_errors () 
    				);
    			} else {
                       //图片相关信息都在这啦,你可以打印一下 $upload = $this->upload->data (); $time = time();
                       //图片上传到服务器后的间路径 $file1 = $config ['upload_path'].$upload ['raw_name'] . '.' . $upload ['image_type'];
                      //改成时间戳后的路径 $titleImg = $config ['upload_path'] . $time . '.' . $upload ['image_type'];
                       //直接rename() 当然我不知更好的方法,所以自己是这么解决的 rename($file1,$titleImg);
                      //将时间戳路径输出 $titleImg = base_url ( $config ['upload_path'].$time . '.' . $upload ['image_type']); }

      

  • 相关阅读:
    python 安装与pip安装
    使用通配符来解决数据1和11、12/13/14的问题
    数据库中一行变多行,拆分数据
    15-哈希表 HashTable
    13-自平衡二分搜索树 AVLTree
    12-并查集 UnionFind
    11-字典树 Trie
    10-线段树 Segment Tree
    09-堆 Heap(最大堆)
    08-映射 Map
  • 原文地址:https://www.cnblogs.com/linglingyang/p/4707264.html
Copyright © 2020-2023  润新知