<?php
Class Upload extends Controller {
function Go () {
if (isset ($_post[' Go ')) {
Class
$config [' upload_path '] = ' album/source ';
$config [' allowed_types '] = ' gif|jpg|png|bmp|jpeg ';
$config [' encrypt_name '] = TRUE;
$config [' remove_spaces '] = TRUE;
$config [' max_size '] = ' 0 ';
$config [' max_width '] = ' 0 ';
$config [' max_height '] = ' 0 ';
$this->load->library (' upload ', $config);
170*170 Pictures
$configThumb = Array ();
$configThumb [' image_library '] = ' gd2 ';
$configThumb [' source_image '] = ';
$configThumb [' create_thumb '] = TRUE;
$configThumb [' maintain_ratio '] = TRUE; Maintain picture proportions
$configThumb [' new_image '] = ' album/thumb ';
$configThumb [' width '] = 170;
$configThumb [' height '] = 170;
600*600 Pictures
$configLarge = Array ();
$configLarge [' image_library '] = ' gd2 ';
$configLarge [' source_image '] = ';
$configLarge [' create_thumb '] = TRUE;
$configLarge [' maintain_ratio '] = TRUE; Maintain picture proportions
$configLarge [' new_image '] = ' album/large ';
$configLarge [' width '] = 600;
$configLarge [' height '] = 600;
$this->load->library (' image_lib ');
for ($i = 1; $i < 6; $i + +) {
$upload = $this->upload->do_upload (' image '. $i);
if ($upload = = FALSE) continue;
$data = $this->upload->data ();//Returns an array of all relevant information about the uploaded file
$uid = $this->session->userdata (' uid ');
$uploadedFiles [$i] = $data;
if ($data [' is_image '] = = 1) {
Initialize 170*170
$configThumb [' source_image '] = $data [' Full_path ']; File path with file name
$this->image_lib->initialize ($CONFIGTHUMB);
$this->image_lib->resize ();
Initialize 600*600
$configLarge [' source_image '] = $data [' Full_path ']; File path with file name
$this->image_lib->initialize ($configLarge);
$this->image_lib->resize ();
}
Insert picture information to album table, insert file name as source directory filename
$picture = Array (
' filename ' => $data [' file_name '],
' albumID ' => $this->uri->segment (4,0),
' UID ' => $this->session->userdata (' uid '),
' Dateline ' => time (),
' Describe ' => ',
' Click ' => 0
);
$this->load->model (' Album_model ');
$this->album_model->addpic ($picture);
$picture = Array ();
}
}
* * Turn out * *
$albumID = $this->uri->segment (4);
$backurl = Site_url (). ' photo/editpic/album/'. $albumID;
$this->session->set_flashdata (' msg ', ' picture upload succeeded. ')
Redirect ($backurl, ' refresh ');
}
}
1. To upload several files at a time, modify the form and the parameters of the loop part of the controller. The
2.album\\source is uploaded after the original catalogue large and thumb are two executions respectively $this->image_lib->resize (), and the directory after which the thumbnails are stored
3. The thumbnail file name should be consistent with the Album\\source directory, add the parameter $config [' thumb_marker '] = ';
4. $picture This part of the array is saved to the database something that can be used without a tube.