3

I added this line in ./system/application/config/mimes.php

'dwg' => array('application/acad', 'application/x-acad', 'application/autocad_dwg', 'image/x-dwg', 'application/dwg', 'application/x-dwg', 'application/x-autocad', 'image/vnd.dwg', 'drawing/dwg'),

I tried to upload a .dwg file but it shows an error like this:

The filetype you are attempting to upload is not allowed.

How can I upload a .dwg file?

Wesley Murch
  • 101,186
  • 37
  • 194
  • 228
Anil Sharma
  • 489
  • 2
  • 7
  • 15

2 Answers2

2

The file extension dwg must be in your allowed_types:

$config['allowed_types'] = 'dwg';
$this->load->library('upload', $config);

If you want to allow multiple types, they must be pipe | delimited:

$config['allowed_types'] = 'dwg|dxf|dwf';

Reference: http://codeigniter.com/user_guide/libraries/file_uploading.html

Although it appears to be undocumented in the current user guide, using an asterisk * will allow all types:

$config['allowed_types'] = '*';
Wesley Murch
  • 101,186
  • 37
  • 194
  • 228
  • i have already done all the things you mentioned above; Oh and i tried `$config['allowed_types'] = '*';` as well. But it still didn't help me out :( – Anil Sharma Feb 28 '12 at 07:03
  • Can you post your actual code with the upload config and an example file name if possible? Have you made sure you can upload other file types? – Wesley Murch Feb 28 '12 at 07:05
  • Config: `$config['file_name'] = date('YmdHis').'_'.rand(0,9).'.'.$this->getFileExt($fieldName); $config['upload_path'] = realpath('./uploads/client/bi/'); $config['allowed_types'] = 'dxf|dwg|dwf|gif|jpg|png|jpeg'; $config['max_size'] = '2000';` and i have changed the mime setting by adding following lines; `'dwf' => array('drawing/x-dwf', 'model/vnd.dwf'),'dwg' => array('application/acad', 'image/vnd.dwg', 'image/x-dwg'), 'dxf' => array('application/dxf', 'image/vnd.dwg', 'image/x-dwg')`.Now it uploads images perfectly but shows error while trying autocad files. – Anil Sharma Feb 28 '12 at 08:18
  • and i am using this file for test: http://download.autodesk.com/us/samplefiles/acad/visualization_-_aerial.dwg – Anil Sharma Feb 28 '12 at 08:36
  • Those mime types simply didn't work for me. I used `application/octet-stream` and tried, it worked ! I solved the problem but still wondering why those mime types didn't work?! – Anil Sharma Feb 28 '12 at 10:24
  • @AnilSharma: If that was the solution, post your own answer. After a couple days, you can accept it. This will help people having the same problem. – Wesley Murch Feb 28 '12 at 17:23
  • What do you mean? It's not allowing you to post your own answer? – Wesley Murch Feb 29 '12 at 09:03
  • It has just allowed ! I have posted the answer. – Anil Sharma Feb 29 '12 at 09:16
2

Solution :

Those mime types simply didn't work for me. I just used application/octet-stream and tried, it worked ! I solved the problem but still wondering why those mime types didn't work? !

Anil Sharma
  • 489
  • 2
  • 7
  • 15
  • For those reading this years later:- this answer is highly unrecommended. `application/octet-stream` is the mime type equivalent of 'miscellaneous', therefore the server could still be tricked into running malicious code (e.g. an exe) Please see https://www.owasp.org/index.php/PHP_Security_Cheat_Sheet#File_uploads to gain more of an insight. – Jarrod Sep 02 '15 at 12:50
  • I agree with u. It was a question from almost 5 years ago while I was facing this issue for the first time. Anyways, thanks for the reply. – Anil Sharma Jan 20 '17 at 20:09