CodeIgniter Forums
Add MIME (upload .msg file) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Add MIME (upload .msg file) (/showthread.php?tid=929)



Add MIME (upload .msg file) - Walle - 01-30-2015

Hello,

I would like to add a MIME to my project, but I think I'm doing something wrong. I want to upload a .msg file to the database, but apparently .msg files aren't allowed.

This is my upload function:

PHP Code:
private function _do_upload() {
        if (isset(
$_FILES['attachement']) && is_uploaded_file($_FILES['attachement']['tmp_name'])) {
            
$config['upload_path'] = './uploads/';
            
$config['allowed_types'] = 'gif|jpg|png|zip|pdf|doc|docx|msg|txt|xls|xlsx|xml|csv'
            
$this->load->library('upload'$config);
            if (
$this->upload->do_upload('attachement')) {
                return 
$this->upload->data();
            } else {
                
$error = array('error' => $this->upload->display_errors());
                
var_dump($error);
                
var_dump($_FILES);
                die();
                return 
$error;
            }
        } else {
            return 
null;
        }
    } 

In the mimes.php file, I added this line to the array:

Code:
'msg'    =>    array('application/vnd.ms-outlook','application/octet-stream')

I also edited my .htaccess file. It looks like this now:

Code:
Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(connect\.php|index\.php|images|assets|uploads|cgi-bin|robots\.txt|info\.php)
RewriteRule ^(.*)$ index.php/$1 [L]
<FilesMatch "^.ht">
  order allow,deny
  deny from all
</FilesMatch>
AddType application/vnd.ms-outlook msg

Next to that, I also edited my mimes.types file in the folder /etc/. I added this line of code:

Code:
application/vnd.ms-outlook                msg

In the upload.php file in the function do_upload I added a popup box:

PHP Code:
$this->file_type preg_replace("/^(.+?);.*$/""\\1"$this->file_type);
$this->file_type strtolower(trim(stripslashes($this->file_type), '"'));
echo 
"<script type='text/javascript'>alert('$this->file_type');</script>"

When it shows up, it says

Quote:cdf v2 document, corrupt: cannot read summary info

Can anyone help me, or point out what I'm doing wrong? It would help me out a lot!

Thanks in advance,

Walle


RE: Add MIME (upload .msg file) - Avenirer - 01-30-2015

Maybe you don't have the right mime type... Did you first try to see if the file's mime type is the correct one? Try echoing it with PHP function mime_content_type($filepath). Also, did you take a look in here? http://stackoverflow.com/questions/17853623/wrong-type-returned-by-finfo


RE: Add MIME (upload .msg file) - Walle - 02-02-2015

I tried echoing with mime_content_type, and I got 'CDF V2 Document, corrupt: Cannot read summary info' again. It does work for other files though (tried it with 'index.php', and it works with that).

I already checked that link before I asked my question here, if I add those lines into my .htaccess file, then I still get the same message: 'CDF V2 Document, corrupt: Cannot read summary info'. But my guess is, that the link is a solution for .docx files. Not for .msg files.