Welcome Guest, Not a member yet? Register   Sign In
docx file mime type vaidation
#1

Hello,

I'm facing a problem with mime type validation of a docx file uploaded,
the mime : application/vnd.openxmlformats-officedocument.wordprocessingml.document

It's work fine only with PDF and plan text:

Also a problem with the method :  
PHP Code:
$file->getClientMimeType(); 


I'm not able te see echo out the mime type of JPG, JPEG, DOX, DOC it's work only with PDF and txt file why? 

This is how i use the validation  :

PHP Code:
$file = $this->request->getFile('info_cert');
/*
echo '<br> <b>MIME TYPE</b><br>';                    
echo $file->getClientMimeType();
echo '<br> <b> / MIME TYPE</b><br>';*/
$docx = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'// I use it as variable just to see i get something but no results also.. 
[font=Input, monospace, Consolas,]$validated = $this->validate([
                        'info_cert' => [
                            'uploaded[info_cert]',
                            "mime_in[info_cert,image/png,image/jpeg,image/gif,image/png,application/pdf,${docx},application/msword,application/vnd.oasis.opendocument.text,application/epub+zip,application/octet-stream]",
                            'max_size[info_cert,15360]','mime_in[personal_info_blood_cert,docx,doc,jpg,JPG,jpeg,JPEG,pdf,png,epub,rtf]'
                        ],
                    ]);
                    
                    if ($validated)
                    {
                        
                       
                        echo $file->getPath();
                        dd($file);
                        //if ($pdf_blob = fopen($file_tmp, "rb")) {}

                        if($oldRecord  && 0 < $this->request->getPost('user_id'&&  
                        $oldRecord == $this->request->getPost('user_id'&& !empty($personalInfo)){
                        $qbuilder_personalInfo->where('user_id',$oldRecord );
                        $qbuilder_personalInfo->update($personalInfo);

                        return $this->redirectToUserProfile();
                        
                        }else{
                            $personalInfo['user_id'= trim($this->sanitizePostStr($this->request->getPost('user_id')));
                            $qbuilder_personalInfo->insert($personalInfo);
                            return $this->redirectToUserProfile();
                        }
                    }else{
                        echo '<br>not valid<br>';
                    }
[/font]


I don't know maybe the dot not accepted I tried with a backslash like this (vnd\.openxmlformats) but not worked.
Reply
#2

Windows 7, Opera, php 7.3 - works

1. You specify the mime_in rule twice. In the second case, non-mime types are specified and the field is different.
'mime_in[personal_info_blood_cert,docx,doc,jpg,JPG,jpeg,JPEG,pdf,png,epub,rtf]'

2. The mime type is determined through the FileInfo extension or, if it is not added, the type provided by the browser is used.
Reply
#3

getClientMimeType()

Returns the mime type (mime type) of the file as provided by the client.
This is NOT a trusted value. For a trusted version, use getMimeType() instead:


PHP Code:
$type getClientMimeType(); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB