php實(shí)現(xiàn)圖片上傳、剪切功能
本文實(shí)例為大家詳細(xì)介紹了php實(shí)現(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'));
}
/**
* 首頁(yè)
*/
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中如何調(diào)用webservice的實(shí)例參考
本篇文章介紹了,PHP中如何調(diào)用webservice的實(shí)例參考。需要的朋友參考下2013-04-04
PHP無(wú)法訪問(wèn)遠(yuǎn)程mysql的問(wèn)題分析及解決
首先說(shuō)明,遠(yuǎn)程服務(wù)器是可遠(yuǎn)程訪問(wèn)的,經(jīng)過(guò)一番折騰最后想到了SELINUX的問(wèn)題,對(duì)比了下AB兩臺(tái)機(jī)器,果然設(shè)置不一樣!估計(jì)就是它的問(wèn)題2013-05-05
php session 寫入數(shù)據(jù)庫(kù)
這篇文章主要介紹了php session 寫入數(shù)據(jù)庫(kù)的相關(guān)資料,需要的朋友可以參考下2016-02-02
PHP實(shí)現(xiàn)仿Google分頁(yè)效果的分頁(yè)函數(shù)
這篇文章主要介紹了PHP實(shí)現(xiàn)仿Google分頁(yè)效果的分頁(yè)函數(shù),實(shí)例分析了php實(shí)現(xiàn)分頁(yè)的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07
PHP實(shí)現(xiàn)websocket通信的方法示例
這篇文章主要介紹了PHP實(shí)現(xiàn)websocket通信的方法,結(jié)合實(shí)例形式分析了php基于websocket類的socket通信相關(guān)客戶端與服務(wù)器端操作技巧,需要的朋友可以參考下2018-08-08
PHP中使用crypt()實(shí)現(xiàn)用戶身份驗(yàn)證的代碼
在開(kāi)發(fā)PHP應(yīng)用中如果不想自己開(kāi)發(fā)新的加密算法,還可以利用PHP提供的crypt()函數(shù)來(lái)完成單向加密功能2012-09-09

