php實現(xiàn)圖片上傳/剪切功能
來源:易賢網(wǎng) 閱讀:1367 次 日期:2016-08-24 14:53:49
溫馨提示:易賢網(wǎng)小編為您整理了“php實現(xiàn)圖片上傳/剪切功能”,方便廣大網(wǎng)友查閱!

本文實例為大家詳細(xì)介紹了php實現(xiàn)圖片上傳、剪切功能的具體代碼,供大家參考,具體內(nèi)容如下

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Index extends MY_Controller {

  function __construct(){

    parent::__construct();

    $this->load->helper(array('form', 'url'));

  }

  /**

   * 首頁

   */

  public function index() {

    $this->load->view('upload_form', array('error' => ' ' ));

  }

  public function do_upload()

  {

    $config['upload_path']   = './data/uploads/';

    $config['allowed_types']  = 'gif|jpg|png';

    $config['max_size']   = 100;

    $config['max_width']    = 1024;

    $config['max_height']    = 768;

    $this->load->library('upload', $config);

    if ( ! $this->upload->do_upload('userfile'))

    {

      $error = array('error' => $this->upload->display_errors());

      $this->load->view('upload_form', $error);

    }

    else

    {

      $data = array('upload_data' => $this->upload->data());

        

      $this->load->library('image_lib');      

      list($width, $height) = getimagesize($data['upload_data']['full_path']);

      $config['image_library'] = 'gd2';

      $config['source_image'] = $data['upload_data']['full_path'];

      $config['maintain_ratio'] = TRUE;

      if($width >= $height)

      {

        $config['master_dim'] = 'height';

      }else{

        $config['master_dim'] = 'width';

      }

      $config['width'] = 180;

      $config['height'] = 180;

      $this->image_lib->initialize($config);

      $this->image_lib->resize();

      

      $config['maintain_ratio'] = FALSE;

      if($width >= $height)

      {

        $config['x_axis'] = floor(($width * 180 / $height - 180)/2);

      }else{

        $config['y_axis'] = floor(($height * 180 / $width - 180)/2);

      }

      $this->image_lib->initialize($config);

      $this->image_lib->crop();

        

      $this->load->view('upload_success', $data);

    }

  }

}

以上就是本文的全部內(nèi)容,希望對大家學(xué)習(xí)php程序設(shè)計有所幫助。

更多信息請查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機(jī)網(wǎng)站地址:php實現(xiàn)圖片上傳/剪切功能
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 加入群交流 | 手機(jī)站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65317125(9:00—18:00) 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報警專用圖標(biāo)