国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php實現圖片上傳、剪切功能

2024-09-04 11:46:55
字體:
來源:轉載
供稿:網友

本文實例為大家詳細介紹了php實現圖片上傳、剪切功能的具體代碼,供大家參考,具體內容如下:

  1. <?php 
  2.  
  3. defined('BASEPATH') OR exit('No direct script access allowed'); 
  4.  
  5. //Vevb.com 
  6. class Index extends MY_Controller { 
  7.  
  8.   function __construct(){ 
  9.  
  10.     parent::__construct(); 
  11.  
  12.     $this->load->helper(array('form''url')); 
  13.  
  14.   } 
  15.  
  16.    
  17.  
  18.   /** 
  19.  
  20.    * 首頁 
  21.  
  22.    */ 
  23.  
  24.   public function index() { 
  25.  
  26.     $this->load->view('upload_form'array('error' => ' ' )); 
  27.  
  28.   } 
  29.  
  30.      
  31.  
  32.      
  33.  
  34.   public function do_upload() 
  35.  
  36.   { 
  37.  
  38.     $config['upload_path']   = './data/uploads/'
  39.  
  40.     $config['allowed_types']  = 'gif|jpg|png'
  41.  
  42.     $config['max_size']   = 100; 
  43.  
  44.     $config['max_width']    = 1024; 
  45.  
  46.     $config['max_height']    = 768; 
  47.  
  48.    
  49.  
  50.     $this->load->library('upload'$config); 
  51.  
  52.    
  53.  
  54.     if ( ! $this->upload->do_upload('userfile')) 
  55.  
  56.     { 
  57.  
  58.       $error = array('error' => $this->upload->display_errors()); 
  59.  
  60.    
  61.  
  62.       $this->load->view('upload_form'$error); 
  63.  
  64.     } 
  65.  
  66.     else 
  67.  
  68.     { 
  69.  
  70.       $data = array('upload_data' => $this->upload->data()); 
  71.  
  72.          
  73.  
  74.       $this->load->library('image_lib');       
  75.  
  76.       list($width$height) = getimagesize($data['upload_data']['full_path']); 
  77.  
  78.       $config['image_library'] = 'gd2'
  79.  
  80.       $config['source_image'] = $data['upload_data']['full_path']; 
  81.  
  82.       $config['maintain_ratio'] = TRUE; 
  83.  
  84.       if($width >= $height
  85.  
  86.       { 
  87.  
  88.         $config['master_dim'] = 'height'
  89.  
  90.       }else
  91.  
  92.         $config['master_dim'] = 'width'
  93.  
  94.       } 
  95.  
  96.       $config['width'] = 180; 
  97.  
  98.       $config['height'] = 180; 
  99.  
  100.       $this->image_lib->initialize($config); 
  101.  
  102.       $this->image_lib->resize(); 
  103.  
  104.        
  105.  
  106.       $config['maintain_ratio'] = FALSE; 
  107.  
  108.       if($width >= $height
  109.  
  110.       { 
  111.  
  112.         $config['x_axis'] = floor(($width * 180 / $height - 180)/2); 
  113.  
  114.       }else
  115.  
  116.         $config['y_axis'] = floor(($height * 180 / $width - 180)/2); 
  117.  
  118.       } 
  119.  
  120.       $this->image_lib->initialize($config); 
  121.  
  122.       $this->image_lib->crop(); 
  123.  
  124.          
  125.  
  126.       $this->load->view('upload_success'$data); 
  127.  
  128.     } 
  129.  
  130.   } 
  131.  

以上就是本文的全部內容,希望對大家學習php程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 辽源市| 体育| 永和县| 固阳县| 孟津县| 临澧县| 扬州市| 应用必备| 岗巴县| 宁津县| 开鲁县| 浦城县| 女性| 淮北市| 庆元县| 龙岩市| 三明市| 万盛区| 庄浪县| 南木林县| 大足县| 泰和县| 绥江县| 桓台县| 津南区| 荥阳市| 马公市| 利津县| 井研县| 北辰区| 花莲县| 商丘市| 武夷山市| 灌阳县| 宜丰县| 布尔津县| 石屏县| 青浦区| 邵东县| 贵南县| 兴城市|