{"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

Mime Types Plus – https:\/\/wordpress.org\/plugins\/mime-types-plus\/<\/a><\/p>\n\n\n\n

Co d\u00e1l?<\/h2>\n\n\n\n
\"\"<\/figure>\n\n\n\n

Tento nadpis jsem na z\u00e1v\u011br zvolil z\u00e1m\u011brn\u011b. N\u00e1vody, jako je tento najdete, kdy\u017e budete hledat. A v nich se do\u010dtete jenom to, jak m\u00e1te povolit jin\u00e9 typy soubor\u016f. <\/p>\n\n\n\n

Ok, p\u0159\u00edponu zn\u00e1me, t\u0159eba xlsx, co ale napsat do hodnoty polo\u017eky pole? Kde je n\u011bjak\u00fd seznam? Nen\u00ed. Nebo jsem ho prost\u011b nena\u0161el. <\/p>\n\n\n\n

Av\u0161ak, tento odkaz v\u00e1s zavede p\u0159\u00edmo do \u010d\u00e1sti k\u00f3du, kde je seznam vyps\u00e1n. a tam ji\u017e najdete co pot\u0159ebujete https:\/\/core.trac.wordpress.org\/browser\/tags\/5.4\/src\/wp-includes\/functions.php#L3019<\/a> <\/p>\n","protected":false},"excerpt":{"rendered":"

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. Tento typ souboru nen\u00ed z bezpe\u010dnostn\u00edch d\u016fvod\u016f povolen. 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<\/p>\n","protected":false},"author":1,"featured_media":5562,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,53,19,30,35,37],"tags":[],"class_list":["post-5558","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-navody","category-reseni-problemu","category-snippety","category-wordpress","category-wordpress-zacatecnici","category-zacatecnici"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/5558"}],"collection":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/comments?post=5558"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/5558\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media\/5562"}],"wp:attachment":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media?parent=5558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=5558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=5558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}