Created
January 20, 2018 09:10
-
-
Save danieldsf/1ad580bd76a8ea5349420a253913d768 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 | |
App::uses('Component', 'Controller'); | |
App::uses('Folder', 'Utility'); | |
class UploadComponent extends Component{ | |
const MAX_FILES = 4; | |
const DIR = WWW_ROOT.'upload'.DS; | |
public $endereco_atual = null; | |
public function upload($data = null){ | |
if(!empty($data)){ | |
#if(count($data) > UploadComponent::MAX_FILES){ | |
# #@Todo: melhorar excecao; | |
# throw new NotFoundException("O numero maximo de uploads eh: {$this->max_files}", 1); | |
#} | |
#IF CONTINUE: | |
#foreach ($data as $file) { | |
$file = $data; | |
$error = $file['error']; | |
$size = $file['size']; | |
$filename = $file['name']; | |
$file_tmp_name = $file['tmp_name']; | |
$allowed = array('pdf', 'doc', 'docx'); | |
if(!in_array(substr( strrchr($filename, '.'), 1), $allowed)){ | |
throw new NotFoundException("Format File Denied", 1); | |
}elseif($error || $size == 0){ | |
throw new NotFoundException("Sending Error", 1); | |
}else{ | |
if(!is_dir(UploadComponent::DIR)){ | |
$pasta = new Folder(); | |
$pasta->create(UploadComponent::DIR); | |
} | |
if(is_uploaded_file($file_tmp_name)) { | |
$this->endereco_atual = UploadComponent::DIR.String::uuid().'-'.$filename; | |
move_uploaded_file($file_tmp_name, $this->endereco_atual); | |
} | |
} | |
# | |
#} | |
return $this->endereco_atual; | |
}else{ | |
return false; | |
} | |
} | |
#End of class; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment