확장자가 없는 파일을 워드프레스로 업로드하시겠습니까?
Wordpress 버전: 4.7.9.
define('ALLOW_UNFILTERED_UPLOADS', true);
그 진술서는 에 쓰여졌다.wp-includes/functions.php.
다음 이름의 단순 파일 편집test확장자를 포함하지 않습니다.
vim test
to upload the file which contain no file extension.
파일을 업로드할 때 오류 표시test.
This file type is not allowed. Please try another.
파일 이름 변경test안으로test.txt.
그리고 다음 항목을 추가합니다.wp-includes/functions.php.
add_filter('upload_mimes','custom_upload_mimes');
function custom_upload_mimes ( $existing_mimes=array() ) {
$existing_mimes['txt'] = 'application/txt';
return $existing_mimes;
}
파일test.txt정상적으로 업로드 할 수 있습니다.
설정 파일에서 설정해도 소용없다.wp-config.php.
define('ALLOW_UNFILTERED_UPLOADS', true);
저는 스물네 살짜리 아이를 쓰고 있어요.
여기 제 것이 있습니다./var/www/html//wp-content/themes/twentyfourteen-child/functions.php
<?php
define('ALLOW_UNFILTERED_UPLOADS', true);
function my_theme_enqueue_styles() {
$parent_style = 'twentyfourteen-style'; // This is 'twentyfourteen-style' for the Twenty Fourteen theme.
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
wp_get_theme()->get('Version')
);
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
remove_filter('the_content', 'wptexturize');
remove_filter('the_excerpt', 'wptexturize');
remove_filter('comment_text', 'wptexturize');
?>
효과가 없습니다.
진짜 문제는 WordPress의 백엔드가 아니라 프런트엔드 검증입니다.업로더는 Plupload에 의해 처리되며 기본적으로 WordPress는 사용자가 정의되었는지 여부만 확인합니다.ALLOW_UNFILTERED_UPLOADS프런트 엔드 플러그인의 필터 검증을 값에 맞게 조정하지 않고 업로드 진행 중에 있습니다.아마도 작은 정면 결함일 것이다.
보시다시피 WordPress는 항상 다음과 같은 기본 설정을 렌더링합니다.
var _wpPluploadSettings = {"defaults":{"file_data_name":"async-upload","url":"\/wp-admin\/async-upload.php","filters":{"max_file_size":"268435456b","mime_types":[{"extensions":"jpg,jpeg,jpe,gif,png,bmp,tiff,tif,ico,asf,asx,wmv,wmx,wm,avi,divx,flv,mov,qt,mpeg,mpg,mpe,mp4,m4v,ogv,webm,mkv,3gp,3gpp,3g2,3gp2,txt,asc,c,cc,h,srt,csv,tsv,ics,rtx,css,htm,html,vtt,dfxp,mp3,m4a,m4b,ra,ram,wav,ogg,oga,flac,mid,midi,wma,wax,mka,rtf,js,pdf,class,tar,zip,gz,gzip,rar,7z,psd,xcf,doc,pot,pps,ppt,wri,xla,xls,xlt,xlw,mdb,mpp,docx,docm,dotx,dotm,xlsx,xlsm,xlsb,xltx,xltm,xlam,pptx,pptm,ppsx,ppsm,potx,potm,ppam,sldx,sldm,onetoc,onetoc2,onetmp,onepkg,oxps,xps,odt,odp,ods,odg,odc,odb,odf,wp,wpd,key,numbers,pages"}]},"multipart_params":{"action":"upload-attachment","_wpnonce":"9ee7fbf228"}},"browser":{"mobile":false,"supported":true},"limitExceeded":false};
WordPress가 프론트엔드 설정을 생성하기 위해 호출하는 필터에 접속하여 문제를 수정하기 전에 일시적으로 문제를 해결합니다.plupload_default_settings.
에 필터를 추가합니다.functions.php:
add_filter('plupload_default_settings', function ($settings) {
if (defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS) {
unset($settings['filters']['mime_types']);
}
return $settings;
});
이를 통해 다음 파일을 업로드할 수 있습니다.test업로더를 경유하여WordPress는 이미 백엔드를 체크하고 있기 때문에 WordPress를 WordPress에서 정의하고 있는 한wp-config.php그거ALLOW_UNFILTERED_UPLOADS이true업로드가 올바르게 되어 있어야 합니다.
보안 플러그인 또는 다른 플러그인이 이 플러그인에 덮어쓰기되어 있지 않은지 확인합니다.define('ALLOW_UNFILTERED_UPLOADS', true);:)
먼저 스캔을 하는 것이 좋습니다.ALLOW_UNFILTERED_UPLOADS사이트 파일을 검색하여 무엇이 표시되는지 확인합니다.
또한 아직 최신 버전의 WordPress로 업데이트하십시오. WordPress의 오류 메시지가 표시되는 것과 다릅니다.
이것을 /functions에 붙여넣고 싶지 않습니다.php 파일은 /wp-config.filename 파일에 있습니다.
또는 특정 파일 형식에 대한 MIME을 /functions에 붙여넣어서 작성할 수 있습니다.php 파일입니다.
Chin Leung의 답변은 매우 효과적입니다.단, 주의할 점은 파일 확장자를 업로드할 수 있다는 것입니다.
아래 방법에는 다음이 필요합니다.ALLOW_UNFILTERED_UPLOADSfalse로 설정(또는 단순히 wp-config 또는 functions.disp에서는 설정되지 않음)하여 확장자가 없는 파일을 허용하고 확장자가 허용되지 않습니다.
add_filter('upload_mimes', function ( $mimes ) {
$mimes['*'] = 'text/plain';
return $mimes;
});
add_filter( 'wp_check_filetype_and_ext', function ( $types, $file, $filename, $mimes) {
# If filename doesn't containg a dot '.', allow upload
if( false === strpos( $filename, '.' ) ) {
$types['ext'] = '*';
$types['type'] = 'text/plain';
}
return $types;
}, 10, 4 );
아래 코드를 사용자 머리부분에 추가합니다.wp-config.php파일:
define('ALLOW_UNFILTERED_UPLOADS', true);
참고: 미디어에 새 파일을 업로드하려면 다음 URL로 이동하십시오.
http://example.com/wp-admin/media-new.php
대신:
http://example.com/wp-admin/upload.php
★★★★★★★★★★★★★★에서는upload.php의 검증은Javascript., MIME 타입의 Javascript 에 .
언급URL : https://stackoverflow.com/questions/49066042/upload-file-which-contain-no-extension-into-wordpress
'source' 카테고리의 다른 글
| 'JSON'은 IE에서만 정의되지 않은 오류입니다. (0) | 2023.03.21 |
|---|---|
| WooCommerce 기본 암호 보안 수준 변경 (0) | 2023.03.21 |
| 셀레늄을 어떻게 아약스 반응을 기다리죠? (0) | 2023.03.21 |
| $http.get은 Access-Control-Allow-Origin에서 허용되지 않지만 $.ajax는 허용됩니다. (0) | 2023.03.21 |
| 앵귤러에 모의 주입JS 서비스 (0) | 2023.03.21 |