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']); }

  

 

posted on 2015-08-06 10:31  y_php  阅读(1157)  评论(0编辑  收藏  举报