本文实例为大家详细介绍了PHP实现图片上传、剪切功能的具体代码,供大家参考,具体内容如下
rush:PHP;">
class Index extends MY_Controller {
function construct(){
parent::construct();
$this->load->helper(array('form','url'));
}
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',$con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload-><a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>play_errors());
$this->load->view('upload_form',$error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->library('image_lib');
list($width,$height) = ge<a href="https://www.jb51.cc/tag/timage/" target="_blank" class="keywords">timage</a>size($data['upload_data']['full_path']);
$con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>['image_library'] = 'gd2';
$con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>['source_image'] = $data['upload_data']['full_path'];
$con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>['maintain_ratio'] = TRUE;
if($width >= $height)
{
$con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>['master_dim'] = 'height';
}else{
$con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>['master_dim'] = 'width';
}
$con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>['width'] = 180;
$con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>['height'] = 180;
$this->image_lib->initialize($con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>);
$this->image_lib->resize();
$con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>['maintain_ratio'] = FALSE;
if($width >= $height)
{
$con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>['x_axis'] = floor(($width * 180 / $height - 180)/2);
}else{
$con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>['y_axis'] = floor(($height * 180 / $width - 180)/2);
}
$this->image_lib->initialize($con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>);
$this->image_lib->crop();
$this->load->view('upload_success',$data);
}
}
}