Download assets here
tb_image.sql
CREATE TABLE IF NOT EXISTS `tb_image` (
`ID_image` int(11) NOT NULL AUTO_INCREMENT,
`file_name` varchar(50) NOT NULL,
`file_type` varchar(50) NOT NULL,
`file_path` varchar(50) NOT NULL,
`full_path` varchar(100) NOT NULL,
`raw_name` varchar(50) NOT NULL,
`orig_name` varchar(50) NOT NULL,
`client_name` varchar(50) NOT NULL,
`file_ext` varchar(50) NOT NULL,
`file_size` varchar(10) NOT NULL,
`image_width` varchar(10) NOT NULL,
`image_height` varchar(10) NOT NULL,
`image_type` varchar(10) NOT NULL,
`image_size_str` varchar(50) NOT NULL,
PRIMARY KEY (`ID_image`)
);
Folder Structure
application/
css/
img/
js/
upload/
.htaccess
index.php
.htaccess
RewriteEngine On
RewriteBase /ci_series/
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
RewriteRule ^\.html$ /home/read/?$ [L]
# Remove trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
# Enfore NO www
#RewriteCond %{HTTP_HOST} ^www [NC]
#RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301]
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
./application/config/config.php
$config['index_page'] = '';
./application/config/autoload.php
$autoload['libraries'] = array('database', 'form_validation');
$autoload['helper'] = array('url', 'html');
./application/controllers/multiple.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Multiple extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
$config = array(
'upload_path' => './upload/',
'upload_url' => site_url().'upload/',
'allowed_types' => 'jpg|gif|png',
'overwrite' => false
);
$this->load->library('upload', $config);
if ($this->upload->do_upload('file')) {
$data = $this->upload->data();
$insert_to_database = array(
'file_name' => $data['file_name'],
'file_type' => $data['file_type'],
'file_path' => $data['file_path'],
'full_path' => $data['full_path'],
'raw_name' => $data['raw_name'],
'orig_name' => $data['orig_name'],
'client_name' => $data['client_name'],
'file_ext' => $data['file_ext'],
'file_size' => $data['file_size'],
'image_width' => $data['image_width']
,
'image_height' => $data['image_height'],
'image_type' => $data['image_type'],
'image_size_str' => $data['image_size_str']
);
$this->db->insert('tb_image', $insert_to_database);
redirect('multiple');
}
$data['result'] = $this->db->get('tb_image')->result();
$this->load->view('multiple_upload', $data);
}
}
/* End of file multiple.php */
/* Location: ./application/controllers/multiple.php */
./application/views/multiple_upload.php
// between head tag insert this
<link rel="stylesheet" type="text/css" href="<?=site_url('css/dropzone.css');?>" />
<script type="text/javascript" src="<?=site_url('js/dropzone.js');?>"></script>
<form action="<?=site_url('multiple');?>" class="dropzone"></form>
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
<td></td>
<th align="left">File Name</th>
<th align="left">File Type</th>
<th align="left">Full Path</th>
<th align="left">File Size</th>
</tr>
<?php
foreach ($result as $data) {
echo '<tr>';
echo '<td>'.img(array('src' => 'upload/'.$data->file_name, 'width' => '80', 'height' => '50')).'</td>';
echo '<td>'.$data->file_name.'</td>';
echo '<td>'.$data->file_type.'</td>';
echo '<td>'.$data->full_path.'</td>';
echo '<td>'.$data->file_size.'</td>';
echo '</tr>';
}
?>
</table>
0 comments:
Post a Comment