Skip to content

Instantly share code, notes, and snippets.

@raphaeldealmeida
Created February 13, 2012 17:10
Show Gist options
  • Save raphaeldealmeida/1818360 to your computer and use it in GitHub Desktop.
Save raphaeldealmeida/1818360 to your computer and use it in GitHub Desktop.
<?
$arquivo = isset($_FILES["anexo"]) ? $_FILES["anexo"] : FALSE;
$arquivo_tratado = str_replace("+","-",$arquivo);
if(is_uploaded_file($arquivo_tratado['tmp_name'] && !empty ($erro))
{
$size = $_FILES[$arquivo_tratado]['size'];
if ($size > 10240000){
$erro = "O tamanho maximo para envio de arquivo é de 10M. Por favor tente novamente.";
}
$tipo_validos = array("image/txt", "image/pdf", "image/doc", "image/docx", "image/xls", "image/xlsx",
"image/jpg", "image/png", "image/jpeg", "image/zip", "image/rar");
$extencao = $_FILES[$arquivo_tratado]['type'];
if (array_search($extencao, $tipo_validos) === false){
$erro = "Extenção inválida. Tipo permitidos: txt, pdf, doc, docx, xls, xlsx, jpg, png, jpeg, zip, rar";
}
if($arquivo_tratado)
{
// Gera um nome único para a imagem
$nome = $arquivo_tratado["name"];
// Caminho onde o arquivo ficará
$arquivo_dir = $observacao_resultado_arquivo_path . $nome;
// Upload do arquivo
move_uploaded_file($arquivo_tratado["tmp_name"], $arquivo_dir);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment