Last active
August 29, 2015 14:10
-
-
Save andersonFaro9/e49faa4c8ee948669513 to your computer and use it in GitHub Desktop.
Script para upload de arquivos
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 | |
error_reporting(E_ALL); | |
ini_set("display_errors", 1); | |
if (isset($_FILES ['file'])) { | |
$file = $_FILES['file']; | |
$file_name = $file['name']; | |
$file_tmp = $file['tmp_name']; | |
$file_size = $file['size']; | |
$file_error = $file['error']; | |
$file_ext = explode('.', $file_name); | |
$file_ext = strtolower(end($file_ext)); | |
$file_permission = array('doc', 'docx', '.xls', 'pdf', 'jpg'); | |
if (in_array($file_ext, $file_permission)) { | |
if ($file_error === 0) { | |
if ($file_size < 2000000) { | |
$file_new_name = uniqid('', true) . '.' . $file_ext; | |
$file_destination = 'uploads/' . $file_new_name; | |
if (move_uploaded_file($file_tmp, $file_destination)) { | |
echo '...'; | |
//Gostaria que aqui fosse impresso o arquivo anexado para download | |
} | |
} | |
} | |
} else { | |
echo 'Tipo de arquivo ou tamanho não permitidos'; | |
} | |
} | |
?> | |
<html> | |
<head> | |
</head> | |
<body> | |
<div class="navbar"> | |
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data"> | |
<p><input type="file" name="file"/></p> | |
<p><input name="upload" type="submit" value="Enviar"/></p> | |
</form> | |
</div> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment