Skip to content

Instantly share code, notes, and snippets.

@jlamim
Last active June 20, 2016 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlamim/f1a1cbb10a01c7e7bf6fc43f8de3f464 to your computer and use it in GitHub Desktop.
Save jlamim/f1a1cbb10a01c7e7bf6fc43f8de3f464 to your computer and use it in GitHub Desktop.
Upload múltiplo com DropzoneJS e CodeIgniter - Controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function Index()
{
$this->load->view('welcome_message');
}
public function Upload(){
//carrega a biblioteca de upload do CI
$this->load->library('upload');
//define o caminho para salvar as imagens
$path = './uploads';
//Configuração do upload
//informa o diretorio para salvar as imagens
$config['upload_path'] = $path;
//define os tipos de arquivos suportados
$config['allowed_types'] = 'gif|jpg|jpeg|png';
//define o tamanho máximo do arquivo (em Kb)
$config['max_size'] = '5000';
//verifica se o path é válido, se não for cria o diretório "uploads"
if (!is_dir($path)) {
mkdir($path, 0777, $recursive = true);
}
//Inicializa o método de upload
$this->upload->initialize($config);
//processa o upload e verifica o status
if (!$this->upload->do_upload('file')) {
//Determina o status do header
$this->output->set_status_header('400');
//Retorna a mensagem de erro a ser exibida
echo $this->upload->display_errors(null,null);
} else {
//Determina o status do header
$this->output->set_status_header('200');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment