首頁  >  文章  >  php教程  >  codeigniter 图片上传、剪切

codeigniter 图片上传、剪切

PHP中文网
PHP中文网原創
2016-05-22 17:22:221093瀏覽

codeigniter 图片上传、剪切

<?php
defined(&#39;BASEPATH&#39;) OR exit(&#39;No direct script access allowed&#39;);

class Index extends MY_Controller {
	function __construct(){
        parent::__construct();
        $this->load->helper(array(&#39;form&#39;, &#39;url&#39;));
    }

    /**
     * 首页
     */
    public function index() {
        $this->load->view(&#39;upload_form&#39;, array(&#39;error&#39; => &#39; &#39; ));
    }
    
    
	public function do_upload()
    {
        $config[&#39;upload_path&#39;]      = &#39;./data/uploads/&#39;;
        $config[&#39;allowed_types&#39;]    = &#39;gif|jpg|png&#39;;
        $config[&#39;max_size&#39;]     = 100;
        $config[&#39;max_width&#39;]        = 1024;
        $config[&#39;max_height&#39;]       = 768;

        $this->load->library(&#39;upload&#39;, $config);

        if ( ! $this->upload->do_upload(&#39;userfile&#39;))
        {
            $error = array(&#39;error&#39; => $this->upload->display_errors());

            $this->load->view(&#39;upload_form&#39;, $error);
        }
        else
        {
            $data = array(&#39;upload_data&#39; => $this->upload->data());
            
            $this->load->library(&#39;image_lib&#39;);            
		    list($width, $height) = getimagesize($data[&#39;upload_data&#39;][&#39;full_path&#39;]);
		    $config[&#39;image_library&#39;] = &#39;gd2&#39;;
		    $config[&#39;source_image&#39;] = $data[&#39;upload_data&#39;][&#39;full_path&#39;];
		    $config[&#39;maintain_ratio&#39;] = TRUE;
		    if($width >= $height)
		    {
		        $config[&#39;master_dim&#39;] = &#39;height&#39;;
		    }else{
		        $config[&#39;master_dim&#39;] = &#39;width&#39;;
		    }
		    $config[&#39;width&#39;] = 180;
		    $config[&#39;height&#39;] = 180;
		    $this->image_lib->initialize($config);
		    $this->image_lib->resize();
		
		    $config[&#39;maintain_ratio&#39;] = FALSE;
		    if($width >= $height)
		    {
		        $config[&#39;x_axis&#39;] = floor(($width * 180 / $height - 180)/2);
		    }else{
		        $config[&#39;y_axis&#39;] = floor(($height * 180 / $width - 180)/2);
		    }
		    $this->image_lib->initialize($config);
		    $this->image_lib->crop();
		    
            $this->load->view(&#39;upload_success&#39;, $data);
        }
    }
}

                   

 以上就是codeigniter 图片上传、剪切的内容,更多相关内容请关注PHP中文网(www.php.cn)!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn