Skip to content

Instantly share code, notes, and snippets.

@maykelsb
Forked from anonymous/gist:6064061
Last active December 20, 2015 03:29
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 maykelsb/6064074 to your computer and use it in GitHub Desktop.
Save maykelsb/6064074 to your computer and use it in GitHub Desktop.
function parsePostSegundaEtapa() {
// -- Validando $_POST e $_FILES
if (empty($_POST) ) {
$e = new Exception('Tipo de requisição inválida.');
throw $e;
}
$arquivos = array();
// -- Lista de documentos enviados pelo proponente
$documentos = array('contrato_social', 'rg_e_cpf', 'comp_endereco',
'comp_bancario', 'logo');
foreach ($documentos as $documento) {
if (UPLOAD_ERR_OK !== $_FILES[$documento]['error']) {
$e = new Exception('Não foi possível realizar o envio do arquivo.');
throw $e;
}
list(,$tipo) = explode('.', $_FILES[$documento]['name']);
$arquivos[$documento] = array(
'tmp_name' => $_FILES[$documento]['tmp_name'],
'ext' => $tipo);
}
return $arquivos;
}
...
case 2:
try {
$arquivos = parsePostSegundaEtapa();
$path = realpath(dirname(__FILE__)) . "/anexos/{$_SESSION['corretor']['id']}/";
// -- Criando o diretório de armazenamento dos anexos da proposta
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
// -- Armazenando os arquivos para posterior validação
foreach ($arquivos as $arquivo => $infoArquivo) {
$ext = strtolower($infoArquivo['ext']);
if (!move_uploaded_file($infoArquivo['tmp_name'], "{$path}{$arquivo}.{$ext}")) {
$e = new Exception('Não foi possível realizar o armazenamento do arquivo.');
throw $e;
}
// -- Inserindo arquivo da proposta no banco de dados
// $query = sprintf(<<<QUERY QUERY,);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment