Last active
January 16, 2017 17:48
-
-
Save iagocavalcante/8b583b76e7b20d2a589837b01c3074be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('BASEPATH') OR exit('No direct script access allowed'); | |
if( ! ini_get('date.timezone') ) | |
{ | |
date_default_timezone_set('GMT'); | |
} | |
header('Access-Control-Allow-Origin: *'); | |
class Dashboard extends CI_Controller{ | |
public function __construct(){ | |
parent::__construct(); | |
$this->load->helper('form'); | |
$this->load->model('upload_model'); | |
if(!$this->session->userdata('logado')){ | |
redirect("administration/login"); | |
} | |
} | |
public function index(){ | |
$data['albuns'] = $this->upload_model->consultarTodosAlbuns(); | |
$data['fotos'] = $this->db->get('tb_galeria')->result(); | |
$data['admin'] = $this->db->get('tb_usuarios')->result(); | |
$this->load->view('administration/dashboard', $data); | |
} | |
function mudarStatus(){ | |
$id = $this->input->post('id'); | |
$status = $this->input->post('status'); | |
$this->db->where('id', $id); | |
if($status == "A"){ | |
$this->db->set('status', "D"); | |
$this->db->update('tb_galeria'); | |
}else{ | |
$this->db->set('status', "A"); | |
$this->db->update('tb_galeria'); | |
} | |
redirect(base_url('dashboard')); | |
} | |
function upload(){ | |
$idAlbum = $this->input->post('album'); | |
$nome = $this->db->get_where('tb_albuns', array('id' => $idAlbum)); | |
$nome = $nome->row()->album_nome; | |
$path = FCPATH . '/assets/admin/galeria/'.$nome; | |
$nFiles = count($_FILES['arquivo']['tmp_name']); | |
$files = $_FILES['arquivo']; | |
$errors = array(); | |
for($i = 0; $i < $nFiles; $i++){ | |
if($_FILES['arquivo']['error'][$i] != 0){ | |
$errors[$i][] = 'Não foi possível fazer o upload do arquivo '.$_FILES['arquivo']['name'][$i]; | |
} | |
} | |
if(sizeof($errors) == 0){ | |
$this->load->library('upload'); | |
$config['upload_path'] = $path.'/'; | |
$config['allowed_types'] = 'jpg|jpeg|gif|png'; | |
for ($i=0; $i < $nFiles; $i++) { | |
$_FILES['arquivo']['name'] = $files['name'][$i]; | |
$_FILES['arquivo']['type'] = $files['type'][$i]; | |
$_FILES['arquivo']['tmp_name'] = $files['tmp_name'][$i]; | |
$_FILES['arquivo']['error'] = $files['error'][$i]; | |
$_FILES['arquivo']['size'] = $files['size'][$i]; | |
//now we initialize the upload library | |
$this->upload->initialize($config); | |
if ($this->upload->do_upload('arquivo')) { | |
$data['uploads'][$i] = $this->upload->data(); | |
$fotos = array('path' => $data['uploads'][$i]['file_path'], 'ft_nome' => $data['uploads'][$i]['file_name'], 'status' => "A", 'idAlbum' => $idAlbum ); | |
$this->upload_model->inserirImagens($fotos); | |
} else { | |
$data['upload_errors'][$i] = $this->upload->display_errors(); | |
} | |
} | |
redirect(base_url('dashboard')); | |
} else { | |
redirect(base_url('administration/dashboard', $errors)); | |
} | |
/*$configup['upload_path'] = FCPATH . '/assets/admin/galeria/'; | |
$configup['allowed_types'] = 'jpg|png|gif'; | |
$this->load->library('upload', $configup); | |
if ( ! $this->upload->do_upload('arquivo')) { | |
$error = array('error' => $this->upload->display_errors()); | |
redirect(base_url('administration/dashboard', $error)); | |
} else { | |
$fotos['path'] = $this->upload->data('full_path'); | |
$fotos['ft_nome'] = $this->upload->data('file_name'); | |
$fotos['status'] = "A"; | |
$this->upload_model->inserirImagens($fotos); | |
redirect(base_url('dashboard')); | |
} | |
*/ | |
} | |
function cadastrarAlbum(){ | |
$nome = $this->input->post('nomeAlbum'); | |
$album = array('id' => NULL, 'album_nome' =>strtolower($nome)); | |
$path = FCPATH . '/assets/admin/galeria/'; | |
if (!is_dir($path)) { | |
mkdir($path, 0777, true); | |
} | |
$dir_exist = true; // flag for checking the directory exist or not | |
if (!is_dir($path . strtolower($nome))) { | |
mkdir($path . strtolower($nome), 0777, true); | |
$dir_exist = false; // dir not exist | |
} | |
$this->db->insert('tb_albuns', $album ); | |
redirect(base_url('dashboard')); | |
} | |
function consultarId(){ | |
$id = $this->input->post('id'); | |
$this->db->select('*'); | |
$this->db->from('tb_albuns'); | |
$this->db->join('tb_galeria', 'tb_galeria.idAlbum = tb_albuns.id'); | |
$this->db->where('tb_albuns.id', $id); | |
$data[] = $this->db->get()->result(); | |
echo json_encode($data); | |
} | |
function primeiraImg(){ | |
$id = $this->input->post('idAlb'); | |
$this->db->select('*'); | |
$this->db->from('tb_albuns'); | |
$this->db->join('tb_galeria', 'tb_galeria.idAlbum = tb_albuns.id'); | |
$this->db->where('tb_albuns.id', $id); | |
$this->db->order_by('tb_albuns.id', 'DESC'); | |
$this->db->limit(1); | |
$pImg[] = $this->db->get()->result(); | |
echo json_encode($pImg); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Codigo para upload e consulta de imagens