Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. public function validar_arquivo() {
  2. // Valida o arquivo enviado, e quando incorreto retorna false
  3. if(isset($_FILES['arquivo'])) {
  4. // Valida o tamanho, 3145728 bytes = 3072 kB = 3 MB
  5. if($_FILES['arquivo']['size'] > 3145728) {
  6. echo('O tamanho do arquivo deve ser inferior ou igual a 3,00 MB.');
  7. return false;
  8. }
  9.  
  10. // Valida o conteúdo do arquivo
  11. if($_FILES['arquivo']['tmp_name']) {
  12. $file_data = file_get_contents($_FILES['arquivo']['tmp_name']);
  13. if(substr($file_data, 0, 6) == '%PDF-1') {
  14. echo('application/pdf');
  15. } else if(exif_imagetype($_FILES['arquivo']['tmp_name']) == IMAGETYPE_JPEG) {
  16. echo('image/jpeg');
  17. } else if(exif_imagetype($_FILES['arquivo']['tmp_name']) == IMAGETYPE_PNG) {
  18. echo('image/png');
  19. } else {
  20. echo('O arquivo enviado não está no formato esperado: arquivo PDF, imagem JPG ou imagem PNG.');
  21. return false;
  22. }
  23. }
  24.  
  25. }
  26. return true;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement