Rumah > php教程 > PHP源码 > codeigniter 图片上传、剪切

codeigniter 图片上传、剪切

PHP中文网
Lepaskan: 2016-05-22 17:22:22
asal
1151 orang telah melayarinya

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);
        }
    }
}
Salin selepas log masuk

                   

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

sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Cadangan popular
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan