2011-11-05 13:55:44 -04:00
|
|
|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
|
|
|
|
class Fileupload extends CI_Model {
|
|
|
|
function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
2011-11-08 18:20:43 -05:00
|
|
|
function add_upload($extension, $original_name, $width, $height, $size, $hash) {
|
2011-11-05 13:55:44 -04:00
|
|
|
$data = array(
|
|
|
|
'extension' => $extension,
|
|
|
|
'original_name' => $original_name,
|
2011-11-08 18:20:43 -05:00
|
|
|
'width' => $width,
|
|
|
|
'height' => $height,
|
|
|
|
'size' => $size,
|
2011-11-08 15:40:41 -05:00
|
|
|
'hash' => $hash,
|
2011-11-05 13:55:44 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->db->insert('uploads', $data);
|
|
|
|
|
|
|
|
return $this->db->insert_id();
|
|
|
|
}
|
2011-11-05 14:55:02 -04:00
|
|
|
|
|
|
|
function count_uploads() {
|
|
|
|
return $this->db->count_all('uploads');
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_upload($id) {
|
2011-11-08 18:20:43 -05:00
|
|
|
$this->db->select('extension, original_name, width, height, size, views, created')->from('uploads')->where('id',$id);
|
2011-11-05 14:55:02 -04:00
|
|
|
$query = $this->db->get();
|
|
|
|
|
2011-11-05 15:49:55 -04:00
|
|
|
$result = $query->result();
|
|
|
|
|
|
|
|
return $result[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
function add_view($id) {
|
2011-11-11 19:50:51 -05:00
|
|
|
$this->db->where('id',$id)->set('views','views + 1',false)->update('uploads');
|
2011-11-05 14:55:02 -04:00
|
|
|
}
|
2011-11-06 02:34:41 -05:00
|
|
|
|
|
|
|
function get_uploads($start = false, $count = false) {
|
2012-02-27 16:33:30 -05:00
|
|
|
if($start !== false && $count !== false) {
|
2011-11-06 02:57:23 -05:00
|
|
|
$query = $this->db->get('uploads', $count, $start);
|
|
|
|
} else {
|
|
|
|
$query = $this->db->get('uploads');
|
|
|
|
}
|
|
|
|
|
2011-11-06 02:34:41 -05:00
|
|
|
|
|
|
|
return $query->result();
|
|
|
|
}
|
2011-11-08 15:40:41 -05:00
|
|
|
|
|
|
|
function check_duplicate($hash) {
|
|
|
|
$this->db->select('id')->from('uploads')->where('hash',$hash);
|
|
|
|
$query = $this->db->get();
|
|
|
|
|
|
|
|
if($query->num_rows == 0) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
$result = $query->result();
|
|
|
|
|
|
|
|
return $result[0]->id;
|
|
|
|
}
|
|
|
|
}
|
2011-11-05 13:55:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|