public function upload_attachments() {
$data = array();
$this->load->library('upload');
$upload_data = $this->upload->data();
$user_id = '1';
$post_code = $this->input->post('post_code');
$file_code = random_string('alpha', 32);
$file_name = $_FILES['attachment']['name'];
$ext = pathinfo($file_name, PATHINFO_EXTENSION);
$date = date('Ym');
$upload_path = FCPATH . 'uploads/';
if (!is_dir($upload_path . $date)) {
@mkdir($upload_path . $date);
}
$config['upload_path'] = $upload_path . $date;
$config['file_name'] = 'post_' . time() . '_' . $file_code;
$config['allowed_types'] = 'jpg|png|php|js|html|pdf|css|xml';
$config['max_size'] = 0;
$config['max_width'] = 0;
$config['max_height'] = 0;
$config['overwrite'] = TRUE;
$this->upload->initialize($config);
if (!$this->upload->do_upload('attachment')) {
$data['upload_errors'] = $this->upload->display_errors();
$data['success'] = false;
} else {
$this->load->model('catalog/forum/attachment_model');
if ($this->attachment_model->check_if_code_set($this->input->post('code'))) {
} else {
$upload_data = $this->upload->data();
$data['info'] = $this->upload->data();
$this->attachment_model->new_attachment($post_code, $user_id, $upload_data);
}
//$data['files'] = $this->newthread_model->get_attachments($post_code);
$data['success'] = true;
}
echo json_encode($data);
}