-
-
Save maykelsb/6064074 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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