문제

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?

도움이 되었습니까?

해결책

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');

다른 팁

If it can help: to fix the Due to safety reasons this file type is not allowed error

you need to add this in the wp-config.php :

define('ALLOW_UNFILTERED_UPLOADS', true);

The dwg mimes are multiple, you should add all these:

function custom_upload_mimes ( $existing_mimes=array() ) {
    $existing_mimes['dwg'] = 'image/vnd.dwg';
    $existing_mimes['dwg'] = 'application/acad';
    $existing_mimes['dwg'] = 'application/autocad';
    $existing_mimes['dwg'] = 'application/autocaddwg';
    $existing_mimes['dwg'] = 'application/dwg';
    $existing_mimes['dwg'] = 'drawing/dwg';
    $existing_mimes['dwg'] = 'image/dwg';

    return $existing_mimes;
}
add_filter('upload_mimes', 'custom_upload_mimes');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 wordpress.stackexchange
scroll top