{"id":5558,"date":"2020-05-03T13:31:54","date_gmt":"2020-05-03T13:31:54","guid":{"rendered":"https:\/\/musilda.cz\/?p=5558"},"modified":"2020-05-03T13:31:54","modified_gmt":"2020-05-03T13:31:54","slug":"jak-povolit-zakazane-typy-souboru","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/jak-povolit-zakazane-typy-souboru\/","title":{"rendered":"Jak povolit zak\u00e1zan\u00e9 typy soubor\u016f"},"content":{"rendered":"\n
Nahr\u00e1v\u00e1n\u00ed ur\u010dit\u00fdch typ\u016f soubor\u016f je ve WordPressu z bezpe\u010dnostn\u00edch d\u016fvod\u016f zak\u00e1z\u00e1no. Uk\u00e1\u017eeme si postup, jak povolit nahr\u00e1v\u00e1n\u00ed nap\u0159\u00edklad svg, nebo xlsx soubor\u016f do knihovny m\u00e9di\u00ed.<\/p>\n\n\n\n
Tento typ souboru nen\u00ed z bezpe\u010dnostn\u00edch d\u016fvod\u016f povolen.<\/p><\/blockquote>\n\n\n\n
To je hl\u00e1\u0161ka, kterou n\u00e1m WordPress zobraz\u00ed ve chv\u00edli, kdy se pokus\u00edme do m\u00e9di\u00ed nahr\u00e1t nap\u0159\u00edklad svg ikonu. Soubor s p\u0159\u00edponou svg pat\u0159\u00ed toti\u017e mezi ty, kter\u00e9 jsou blokov\u00e1ny. <\/p>\n\n\n\n
Na\u0161t\u011bst\u00ed, jako spoustu jin\u00fdch v\u011bc\u00ed ve WP to m\u016f\u017eete zm\u011bnit. <\/p>\n\n\n\n
Jak zjistit, kter\u00e9 typy soubor\u016f jsou povoleny?<\/h2>\n\n\n\n
Je na to funkce, kter\u00e1 vr\u00e1t\u00ed pole v\u0161ech povolen\u00fdch typ\u016f. Sta\u010d\u00ed napsat:<\/p>\n\n\n\n
print_r( get_allowed_mime_types() );<\/code><\/pre>\n\n\n\n
a vyp\u00ed\u0161\u00ed se v\u00e1m v\u0161echny povolen\u00e9 soubory. <\/p>\n\n\n\n
Jak povolit dal\u0161\u00ed tipy soubor\u016f?<\/h2>\n\n\n\n
V\u00fd\u0161e zm\u00edn\u011bn\u00e1 funkce m\u00e1 filtr pomoc\u00ed kter\u00e9ho m\u016f\u017eete roz\u0161\u00ed\u0159it pole povolen\u00fdch typ\u016f:<\/p>\n\n\n\n
upload_mimes<\/code><\/pre>\n\n\n\n
P\u0159ij\u00edm\u00e1 dva argumenty – pole typ\u016f a u\u017eivatele. U\u017eivatele proto, \u017ee kontroluje zda m\u00e1 opr\u00e1vn\u011bn\u00ed pro nahr\u00e1v\u00e1n\u00ed nefiltrovan\u00e9ho html:<\/p>\n\n\n\n
user_can( $user, 'unfiltered_html' )<\/code><\/pre>\n\n\n\n
Pokud toto opr\u00e1vn\u011bn\u00ed nem\u00e1, tak z pole povolen\u00fdch soubor\u016f odstran\u00ed html a js. <\/p>\n\n\n\n
Pro povolen\u00ed dal\u0161\u00edch typ\u016f sta\u010d\u00ed pou\u017e\u00edt prvn\u00ed argument filtru $types, co\u017e je pole, kde kl\u00ed\u010d je p\u0159\u00edpona souboru a hodnota je jeho typ:<\/p>\n\n\n\n
'rar' => 'application\/rar',<\/code><\/pre>\n\n\n\n
Pokud tedy chcete roz\u0161\u00ed\u0159it pole povolen\u00fdch soubor\u016f, pou\u017eijete filtr takto:<\/p>\n\n\n\n
add_filter( 'upload_mimes', 'expand_upload_mimes', 10, 1 );\nfunction expand_upload_mimes( $mimes ){\n\n $mimes['csv'] = 'text\/csv';\n\n return $mimes;\n\n}<\/code><\/pre>\n\n\n\n
T\u00edm roz\u0161\u00ed\u0159\u00edte pole o dal\u0161\u00ed polo\u017eku a povol\u00edte csv soubory. <\/p>\n\n\n\n
Pluginy<\/h2>\n\n\n\n
Proto\u017ee se jedn\u00e1 o pom\u011brn\u011b jednoduchou z\u00e1le\u017eitost, existuj\u00ed na to i pluginy, kter\u00e9 v\u00e1m to umo\u017en\u00ed povolit z administrace. Zde jsou dva z nich. <\/p>\n\n\n\n
WP Add Mime Types – https:\/\/cs.wordpress.org\/plugins\/wp-add-mime-types\/<\/a><\/p>\n\n\n\n