Move redundant image_lib config to a file. Same does not seem to work for upload library.
This commit is contained in:
parent
8c0c91b52e
commit
c0558284b5
3 changed files with 34 additions and 16 deletions
10
application/config/image_lib.php
Normal file
10
application/config/image_lib.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
$config = array(
|
||||||
|
'image_library' => 'gd2',
|
||||||
|
'create_thumb' => true,
|
||||||
|
'maintain_ratio' => true,
|
||||||
|
'width' => 175,
|
||||||
|
'height' => 175,
|
||||||
|
'thumb_marker' => '',
|
||||||
|
);
|
||||||
|
?>
|
7
application/config/upload.php
Normal file
7
application/config/upload.php
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
// $config = array(
|
||||||
|
// 'max_size' => 2048,
|
||||||
|
// 'upload_path' => './uploads/',
|
||||||
|
// 'allowed_types' => 'gif|jpg|jpeg|png|bmp'
|
||||||
|
// );
|
||||||
|
?>
|
|
@ -10,24 +10,27 @@ class Upload extends CI_Controller {
|
||||||
|
|
||||||
$temp_name = md5(rand());
|
$temp_name = md5(rand());
|
||||||
|
|
||||||
|
// cannot move partial config to config directory with this class?
|
||||||
$config = array(
|
$config = array(
|
||||||
'file_name' => $temp_name,
|
|
||||||
'max_size' => 2048,
|
'max_size' => 2048,
|
||||||
'upload_path' => './uploads/',
|
'upload_path' => './uploads/',
|
||||||
'allowed_types' => 'gif|jpg|jpeg|png|bmp'
|
'allowed_types' => 'gif|jpg|jpeg|png|bmp'
|
||||||
);
|
);
|
||||||
|
// end stuff that should be removed.
|
||||||
|
$config['file_name'] = $temp_name;
|
||||||
|
|
||||||
$this->load->library('upload', $config);
|
$this->load->library('upload');
|
||||||
|
$this->upload->initialize($config);
|
||||||
|
|
||||||
if (!$this->upload->do_upload('image')) {
|
if (!$this->upload->do_upload('image')) {
|
||||||
$message = array('type' => 'error', 'status' => $this->upload->display_errors());
|
$message = array('type' => 'error', 'status' => $this->upload->display_errors());
|
||||||
} else {
|
} else {
|
||||||
$upload = $this->upload->data();
|
$upload = $this->upload->data();
|
||||||
|
|
||||||
$hash = md5_file($upload['full_path']);
|
$hash = md5_file($upload['full_path']);
|
||||||
$width = $upload['image_width'];
|
$width = $upload['image_width'];
|
||||||
$height = $upload['image_height'];
|
$height = $upload['image_height'];
|
||||||
$size = $upload['file_size'];
|
$size = $upload['file_size'];
|
||||||
|
|
||||||
$this->load->model('fileupload');
|
$this->load->model('fileupload');
|
||||||
$duplicate = $this->fileupload->check_duplicate($hash);
|
$duplicate = $this->fileupload->check_duplicate($hash);
|
||||||
|
@ -35,24 +38,22 @@ class Upload extends CI_Controller {
|
||||||
if($duplicate) {
|
if($duplicate) {
|
||||||
unlink($upload['full_path']);
|
unlink($upload['full_path']);
|
||||||
|
|
||||||
$message = array('type'=>'error', 'status'=>'You are attempting to upload a duplicate of <a href="' . base_url($duplicate) . '" style="text-decoration:underline">image ' . $duplicate . '</a>.');
|
$message = array(
|
||||||
|
'type' => 'error',
|
||||||
|
'status' =>'You are attempting to upload a duplicate of <a href="' . base_url($duplicate) . '" style="text-decoration:underline">image ' . $duplicate . '</a>.'
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
$file_name = $this->fileupload->add_upload($upload['file_ext'], $upload['client_name'],$width,$height,$size,$hash);
|
$file_name = $this->fileupload->add_upload($upload['file_ext'], $upload['client_name'],$width,$height,$size,$hash);
|
||||||
|
|
||||||
rename($upload['full_path'], $upload['file_path'] . $file_name . $upload['file_ext']);
|
rename($upload['full_path'], $upload['file_path'] . $file_name . $upload['file_ext']);
|
||||||
|
|
||||||
$config = array(
|
$config = array(
|
||||||
'image_library' => 'gd2',
|
'source_image' => $upload['file_path'] . $file_name . $upload['file_ext'],
|
||||||
'source_image' => $upload['file_path'] . $file_name . $upload['file_ext'],
|
'new_image' => './thumbs/' . $file_name . $upload['file_ext'],
|
||||||
'create_thumb' => true,
|
|
||||||
'maintain_ratio' => true,
|
|
||||||
'width' => 175,
|
|
||||||
'height' => 175,
|
|
||||||
'new_image' => './thumbs/' . $file_name . $upload['file_ext'],
|
|
||||||
'thumb_marker' => '',
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->load->library('image_lib',$config);
|
$this->load->library('image_lib');
|
||||||
|
$this->image_lib->initialize($config);
|
||||||
$this->image_lib->resize();
|
$this->image_lib->resize();
|
||||||
|
|
||||||
$message = array('type'=>'success','status'=>'Uploaded successfully', 'file'=>base_url($file_name));
|
$message = array('type'=>'success','status'=>'Uploaded successfully', 'file'=>base_url($file_name));
|
||||||
|
|
Loading…
Reference in a new issue