英文:
Allow uploading only one format in WordPress
问题
如何阻止上传所有格式,只允许上传一种格式?
使用以下代码,您可以阻止上传所需的格式,但是使用此代码可能会忘记阻止某种格式。我想创建一个条件,如果文件是jpg格式,则允许上传,不允许上传除jpg之外的任何格式。这样,我就不再需要搜索每种格式并阻止它们。
function cc_mime_types( $mimes ) {
unset( $mimes['png'] );
return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
英文:
How to block upload of all formats, allow only one format to upload?
With the following code, you can block the upload of the desired formats, But with this code I might forget to block a format, I want to make a condittion that if the file was in jpg format, it would upload and not allow uploading any format other than jpg. In this way, I no longer need to search for each format and block them.
function cc_mime_types( $mimes ) {
unset( $mimes['png'] );
return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
答案1
得分: 1
以下是已翻译好的代码部分:
With the help of my good friend **CBroe**, my problem was solved with the following code :
function cc_mime_types( $mimes ) {
$mimes = array(
'jpg|jpeg' => 'image/jpeg',
);
return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
CBroe, Thank you very much.
请注意,我已保留了代码的原始格式和标记。
英文:
With the help of my good friend CBroe, my problem was solved with the following code :
function cc_mime_types( $mimes ) {
$mimes = array(
'jpg|jpeg' => 'image/jpeg',
);
return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
CBroe, Thank you very much.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论