1

I am getting an error because of the file extension while uploading a .rar or a .zip. Here is part of my code:

$tipo = $_FILES['archivo']['type'];
$ext_permitidas = array('doc','docx','xls','xlsx','zip','rar','ppt','pptx','pdf');
$partes_nombre = explode('.', $nombre);
$extension = end( $partes_nombre );
$ext_correcta = in_array($extension, $ext_permitidas);
$tipo_correcto = preg_match('/^(application\/(msword|x-rar-compressed|zip|pdf)|application\/vnd\.(ms-excel|ms-powerpoint|openxmlformats-officedocument\.(wordprocessingml\.document|spreadsheetml\.sheet|presentationml\.presentation)))$/', $tipo);
if( $ext_correcta && $tipo_correcto){
#do stuff
}else{
echo 'Invalid file <br><a href="../../../login.php">Return</a> ';
echo $tipo;
}

When I upload the .zip/.rar file I get an error and $tipo is application/octet-stream. One solution I have found for .zip is to put that octet-stream instead of .zip and .rar but inexplicably it only works for .zip... Anyway, I prefer not to put octet-stream becasue it also include .exe files.

How could I get it working?

EDIT: my question differs from that one: .rar, .zip files MIME Type in the point that I want to upload more file extensions that only .rar and .zip and in the point that I have tryed that mime types:

.rar    application/x-rar-compressed, application/octet-stream
.zip    application/zip, application/octet-stream

but I got errors in both of them. I have also tryed that:

application/octet-stream

but it only works for .zip files

Community
  • 1
  • 1
alfuco
  • 55
  • 3
  • 12

0 Answers0