Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function validar_arquivo() {
- // Valida o arquivo enviado, e quando incorreto retorna false
- if(isset($_FILES['arquivo'])) {
- // Valida o tamanho, 3145728 bytes = 3072 kB = 3 MB
- if($_FILES['arquivo']['size'] > 3145728) {
- echo('O tamanho do arquivo deve ser inferior ou igual a 3,00 MB.');
- return false;
- }
- // Valida o conteúdo do arquivo
- if($_FILES['arquivo']['tmp_name']) {
- $file_data = file_get_contents($_FILES['arquivo']['tmp_name']);
- if(substr($file_data, 0, 6) == '%PDF-1') {
- echo('application/pdf');
- } else if(exif_imagetype($_FILES['arquivo']['tmp_name']) == IMAGETYPE_JPEG) {
- echo('image/jpeg');
- } else if(exif_imagetype($_FILES['arquivo']['tmp_name']) == IMAGETYPE_PNG) {
- echo('image/png');
- } else {
- echo('O arquivo enviado não está no formato esperado: arquivo PDF, imagem JPG ou imagem PNG.');
- return false;
- }
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement