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)文章
PHP針對(duì)多用戶實(shí)現(xiàn)更換頭像功能
這篇文章主要介紹了PHP針對(duì)多用戶實(shí)現(xiàn)更換頭像功能的相關(guān)資料,本文分步驟介紹的非常詳細(xì),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-09-09
thinkphp5.1 框架導(dǎo)入/導(dǎo)出excel文件操作示例
這篇文章主要介紹了thinkphp5.1 框架導(dǎo)入/導(dǎo)出excel文件操作,結(jié)合實(shí)例形式分析了thinkphp5.1 框架導(dǎo)入/導(dǎo)出excel文件具體操作實(shí)現(xiàn)技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下2020-05-05
php解析xml 的四種簡(jiǎn)單方法(附實(shí)例)
下面小編就為大家?guī)硪黄猵hp解析xml 的四種簡(jiǎn)單方法(附實(shí)例)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-07-07
php頁面,mysql數(shù)據(jù)庫轉(zhuǎn)utf-8亂碼,utf-8編碼問題總結(jié)
一個(gè)網(wǎng)站如果需要國際化,就需要將編碼從GB2312轉(zhuǎn)成UTF-8,其中有很多的問題需要注意,如果沒有轉(zhuǎn)換徹底,將會(huì)有很多的編碼問題出現(xiàn)!接下來通過本篇文章給大家分享php頁面,mysql數(shù)據(jù)庫轉(zhuǎn)utf-8亂碼,utf-8編碼問題總結(jié),需要的朋友可以參考下2015-08-08
PHP Curl出現(xiàn)403錯(cuò)誤的解決辦法
這篇文章主要介紹了PHP Curl出現(xiàn)403錯(cuò)誤的解決辦法,是一個(gè)比較奇葩的錯(cuò)誤,刪除一些CURL的參數(shù)即可解決這個(gè)問題,需要的朋友可以參考下2014-05-05
使用laravel和ECharts實(shí)現(xiàn)折線圖效果的例子
今天小編就為大家分享一篇使用laravel和ECharts實(shí)現(xiàn)折線圖效果的例子,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-10-10
windows安裝composer并更換國內(nèi)鏡像的過程詳解
這篇文章主要給大家介紹了windows安裝composer并更換國內(nèi)鏡像的過程詳解,文中有詳細(xì)的流程介紹,通過圖文結(jié)合講解的非常詳細(xì),需要的朋友可以參考下2023-11-11

