0

I'm trying to upload files with dwg extension to media but when I do that I get an error telling me that uploading files with this extension is not allowed. I tried to upload them via ftp but I cannot see them in my panel afterwards. I've looked for a solution online and tried adding this to my functions.php:

function custom_upload_mimes ( $existing_mimes=array() ) {
    $existing_mimes[‘dwg’] = ‘application/dwg’;
    return $existing_mimes;
}
add_filter(‘upload_mimes’,’custom_upload_mimes’);

But it didn't change anything. Is there any other way to bypass this file restriction?

  • 1
    Is your actual code using and rather than '? – Jacob Peattie Jun 25 '18 at 7:38
  • Initially it was, later I pasted code @Krzysiek Dróżdż suggested but it didn't help. Now I tried using the code from the original code again but with ' instead but it didn't help either. – aMJay Jun 25 '18 at 7:41
1

Your code should work just fine. The only problem in there is that you’ve set incorrect mime type, I guess...

It should be image/vnd.dwg.

So this one should work:

function custom_upload_mimes ( $existing_mimes=array() ) {
    $existing_mimes['dwg'] = 'image/vnd.dwg';
    return $existing_mimes;
}
add_filter('upload_mimes', 'custom_upload_mimes');
  • Still doesn't work, I'm getting same error which says more or less Due to safety reasons this file type is not allowed. I've pasted this at the top of functions.php, maybe I need to put it in a specific place in code? – aMJay Jun 25 '18 at 6:48
  • Are you sure that you've added it to your active theme? I've just tested that code and it works fine. You can paste it in functions.php file of your theme. – Krzysiek Dróżdż Jun 25 '18 at 7:29
  • I tried pasting into both availible themes to make sure it was not the problem but it didn't help, I'll try bit more maybe I'm missing something obvious – aMJay Jun 25 '18 at 7:36
  • @aMJay where and how exactly are you pasting it? – Krzysiek Dróżdż Jun 25 '18 at 7:43
  • I tried yet another time copying it the way you said and now it works, I have a feeling I've been doing it exactly the same way before but I guess I must have done something wrong earlier, anyway thanks for your help – aMJay Jun 25 '18 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.