php基于CodeIgniter實(shí)現(xiàn)圖片上傳、剪切功能
本文實(shí)例為大家分享了codeigniter 圖片上傳、剪切,控制器類,供大家參考,具體內(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);
}
}
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家學(xué)習(xí)php程序設(shè)計(jì)有所幫助。
相關(guān)文章
thinkphp3.x自定義Action、Model及View的簡(jiǎn)單實(shí)現(xiàn)方法
這篇文章主要介紹了thinkphp3.x自定義Action、Model及View的簡(jiǎn)單實(shí)現(xiàn)方法,結(jié)合實(shí)例形式詳細(xì)分析了thinkPHP3.x自定義模型、視圖及控制器的具體步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-05-05
ThinkPHP框架分布式數(shù)據(jù)庫連接方法詳解
這篇文章主要介紹了ThinkPHP框架分布式數(shù)據(jù)庫連接方法,結(jié)合實(shí)例形式詳細(xì)分析了thinkPHP框架針對(duì)分布式數(shù)據(jù)庫的連接方法、操作技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下2017-03-03
微信公眾平臺(tái)開發(fā)之天氣預(yù)報(bào)功能
這一篇文章將對(duì)大家每天都會(huì)關(guān)心的天氣查詢進(jìn)行開發(fā),例如,用戶發(fā)送消息 “黃岡天氣”,則會(huì)返回黃岡實(shí)時(shí)天氣狀況,以及未來兩天甚至未來五天的天氣狀況。2015-08-08
php5 apache 2.2 webservice 創(chuàng)建與配置(java)
要運(yùn)行wsCaller.jar 要選安裝jdk 如果沒有安裝jdk 則wsCaller.jar 會(huì)以壓縮包的形式顯示2011-01-01
PHP實(shí)現(xiàn)微信提現(xiàn)功能(微信商城)
這篇文章主要介紹了PHP實(shí)現(xiàn)微信提現(xiàn)功能,此類功能在微信商城中經(jīng)常會(huì)用到,今天小編通過實(shí)例代碼給大家講解,需要的朋友可以參考下2019-11-11
PHP開發(fā)框架kohana3 自定義路由設(shè)置示例
這篇文章主要介紹了PHP開發(fā)框架kohana3 自定義路由設(shè)置示例,kohana是一個(gè)純PHP5的開發(fā)框架,需要的朋友可以參考下2014-07-07
超詳細(xì)的php用戶注冊(cè)頁面填寫信息完整實(shí)例(附源碼)
這篇文章主要介紹了一個(gè)超詳細(xì)的php用戶注冊(cè)頁面填寫信息完整實(shí)例,內(nèi)容包括郵箱自動(dòng)匹配、密碼強(qiáng)度驗(yàn)證以及防止表單重復(fù)等,小編特別喜歡這篇文章,推薦給大家。2015-11-11

