{"id":230005,"date":"2022-11-22T17:45:00","date_gmt":"2022-11-22T14:45:00","guid":{"rendered":"https:\/\/wordpress.mediadoma.com\/?p=230005"},"modified":"2022-11-22T20:09:07","modified_gmt":"2022-11-22T17:09:07","slug":"peregljad-zavantazhennja-fajliv-u-wordpress-chastina-2-storona-servera","status":"publish","type":"post","link":"https:\/\/wordpress.mediadoma.com\/uk\/peregljad-zavantazhennja-fajliv-u-wordpress-chastina-2-storona-servera\/","title":{"rendered":"\u041f\u0435\u0440\u0435\u0433\u043b\u044f\u0434 \u0437\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0435\u043d\u043d\u044f \u0444\u0430\u0439\u043b\u0456\u0432 \u0443 WordPress, \u0447\u0430\u0441\u0442\u0438\u043d\u0430 2 \u2013 \u0441\u0442\u043e\u0440\u043e\u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430"},"content":{"rendered":"\n<p>\u041f\u0435\u0440\u0448 \u043d\u0456\u0436 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0431\u0435\u0437\u043f\u043e\u0441\u0435\u0440\u0435\u0434\u043d\u044c\u043e \u0434\u043e \u043a\u043e\u0434\u0443 \u0434\u043b\u044f \u0446\u044c\u043e\u0433\u043e, \u044f \u0445\u043e\u0442\u0456\u0432 \u0431\u0438 \u0437\u0433\u0430\u0434\u0430\u0442\u0438 \u0434\u0432\u0456 \u0440\u0435\u0447\u0456:<\/p>\n<ol>\n<li>\u0422\u0430\u043a, \u0434\u0435\u044f\u043a\u0438\u0439 \u0447\u0430\u0441 \u0442\u043e\u043c\u0443 \u044f \u0440\u043e\u0437\u043f\u043e\u0432\u0456\u0434\u0430\u0432 \u043f\u0440\u043e \u0446\u0435 \u0434\u043e\u0441\u0438\u0442\u044c \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e <strong><a href=\"https:\/\/tommcfarlin.com\/uploading-files-to-a-custom-directory\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">,<\/a><\/strong><\/li>\n<li>\u0406 \u0446\u0435 \u0434\u0440\u0443\u0433\u0430 \u0447\u0430\u0441\u0442\u0438\u043d\u0430 \u0441\u0435\u0440\u0456\u0457 \u0437 \u0434\u0432\u043e\u0445 \u0447\u0430\u0441\u0442\u0438\u043d.<\/li>\n<\/ol>\n<p>\u042f\u043a\u0449\u043e \u0432\u0438 \u043d\u0435 \u0447\u0438\u0442\u0430\u043b\u0438 <a href=\"https:\/\/wordpress.mediadoma.com\/uk\/zavantazhennja-fajliv-u-wordpress-peregljanuto-chastina-1-storona-kliienta\/\" title=\"\u043f\u0435\u0440\u0448\u0443 \u0447\u0430\u0441\u0442\u0438\u043d\u0443\">\u043f\u0435\u0440\u0448\u0443 \u0447\u0430\u0441\u0442\u0438\u043d\u0443<\/a>, \u0437\u0440\u043e\u0431\u0456\u0442\u044c \u0446\u0435 \u0441\u043f\u043e\u0447\u0430\u0442\u043a\u0443. \u0406\u0434\u0435\u044f \u043f\u043e\u043b\u044f\u0433\u0430\u0454 \u0432 \u0442\u043e\u043c\u0443, \u0449\u043e \u043a\u043e\u0434 \u043f\u0440\u0430\u0446\u044e\u0432\u0430\u0442\u0438\u043c\u0435 \u0432 \u043f\u043e\u0454\u0434\u043d\u0430\u043d\u043d\u0456 \u0437 \u0442\u0438\u043c, \u0449\u043e \u044f \u0437\u0431\u0438\u0440\u0430\u044e\u0441\u044f \u0432\u0438\u0441\u0432\u0456\u0442\u043b\u0438\u0442\u0438 \u0432 \u0446\u0456\u0439 \u043f\u0443\u0431\u043b\u0456\u043a\u0430\u0446\u0456\u0457, \u0449\u043e\u0431 \u043f\u0435\u0440\u0435\u043a\u043e\u043d\u0430\u0442\u0438\u0441\u044f, \u0449\u043e \u043e\u0445\u043e\u043f\u043b\u0435\u043d\u043e \u044f\u043a \u043a\u043b\u0456\u0454\u043d\u0442\u0441\u044c\u043a\u0443, \u0442\u0430\u043a \u0456 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u0443 \u0441\u0442\u043e\u0440\u043e\u043d\u0443.<\/p>\n<p>\u0417\u0440\u0435\u0448\u0442\u043e\u044e, \u043f\u0440\u0438\u0447\u0438\u043d\u043e\u044e \u0442\u0430\u043a\u043e\u0457 \u0440\u043e\u0437\u0431\u0438\u0432\u043a\u0438 \u0454 \u043d\u0435 \u0442\u0456\u043b\u044c\u043a\u0438 \u043f\u0435\u0440\u0435\u043a\u043e\u043d\u0430\u0442\u0438\u0441\u044f, \u0449\u043e \u0432\u0441\u0435 \u0437\u0440\u043e\u0431\u043b\u0435\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u0430\u043b\u0435 \u0439 \u043f\u0435\u0440\u0435\u043a\u043e\u043d\u0430\u0442\u0438\u0441\u044f, \u0449\u043e \u043a\u043e\u0440\u0438\u0441\u0442\u0443\u0432\u0430\u0447 \u043c\u0430\u0454 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0437\u0438\u0442\u0438\u0432\u043d\u0438\u0439 \u0434\u043e\u0441\u0432\u0456\u0434.<\/p>\n<p>\u0417 \u043e\u0433\u043b\u044f\u0434\u0443 \u043d\u0430 \u0446\u0435, \u043e\u0441\u044c \u044f\u043a \u0437\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0443\u0432\u0430\u0442\u0438 \u0444\u0430\u0439\u043b\u0438 \u0432 WordPress \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0456 \u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/p>\n<h2>\u0417\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0435\u043d\u043d\u044f \u0444\u0430\u0439\u043b\u0456\u0432 \u0443 WordPress \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0456 \u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/h2>\n<p>\u0417\u0430\u0443\u0432\u0430\u0436\u0442\u0435, \u0449\u043e \u043d\u0430\u0432\u0456\u0442\u044c \u043d\u0435\u0437\u0432\u0430\u0436\u0430\u044e\u0447\u0438 \u043d\u0430 \u043f\u0435\u0432\u043d\u0456 \u043f\u0435\u0440\u0435\u0432\u0456\u0440\u043a\u0438 \u0431\u0435\u0437\u043f\u0435\u043a\u0438, \u044f\u043a\u0456 \u043c\u043e\u0436\u043d\u0430 \u2013 \u0456 \u043f\u043e\u0442\u0440\u0456\u0431\u043d\u043e \u2013 \u0432\u0438\u043a\u043e\u043d\u0443\u0432\u0430\u0442\u0438, \u044f \u0449\u0435 \u043d\u0435 \u0437\u043d\u0430\u0439\u0448\u043e\u0432 \u043f\u043e\u0432\u043d\u0456\u0441\u0442\u044e \u043d\u0430\u0434\u0456\u0439\u043d\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0443 \u0432\u0438\u044f\u0432\u0438\u0442\u0438, \u0449\u043e \u0444\u0430\u0439\u043b, \u044f\u043a\u0438\u0439 \u0437\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0443\u0454\u0442\u044c\u0441\u044f, \u043d\u0430\u043b\u0435\u0436\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0443.<\/p>\n<p>\u0426\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0454, \u0449\u043e \u0432\u0441\u0435 \u0449\u0435 \u0456\u0441\u043d\u0443\u0454 \u0439\u043c\u043e\u0432\u0456\u0440\u043d\u0456\u0441\u0442\u044c \u0437\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0435\u043d\u043d\u044f \u0444\u0430\u0439\u043b\u0443 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0443. \u0427\u0438 \u0454 \u0446\u0435 \u0437\u043b\u043e\u0432\u043c\u0438\u0441\u043d\u0438\u043c \u0447\u0438 \u043d\u0456, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0437\u0430\u043b\u0435\u0436\u0438\u0442\u044c \u0432\u0456\u0434 \u043a\u0456\u043d\u0446\u0435\u0432\u043e\u0433\u043e \u043a\u043e\u0440\u0438\u0441\u0442\u0443\u0432\u0430\u0447\u0430. \u042f \u0434\u0456\u043b\u044e\u0441\u044f \u043b\u0438\u0448\u0435 \u0446\u0438\u043c, \u0449\u043e\u0431 \u0431\u0443\u043b\u043e \u0437\u0440\u043e\u0437\u0443\u043c\u0456\u043b\u043e, \u0449\u043e \u043a\u043e\u0434, \u044f\u043a\u0438\u0439 \u044f \u0437\u0431\u0438\u0440\u0430\u044e\u0441\u044f \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0438, \u043d\u0430\u0441\u0442\u0456\u043b\u044c\u043a\u0438 \u0445\u043e\u0440\u043e\u0448\u0438\u0439, \u043d\u0430\u0441\u043a\u0456\u043b\u044c\u043a\u0438 \u044f \u043c\u043e\u0436\u0443 \u0446\u0435 \u0437\u0440\u043e\u0431\u0438\u0442\u0438, \u0430\u043b\u0435 \u0432\u0438 \u0432\u0441\u0435 \u0449\u0435 \u043c\u0430\u0454\u0442\u0435 \u043f\u0435\u0432\u043d\u0438\u0439 \u0440\u0456\u0432\u0435\u043d\u044c \u043e\u0431\u0435\u0440\u0435\u0436\u043d\u043e\u0441\u0442\u0456.<\/p>\n<p>\u041c\u043e\u0436\u043b\u0438\u0432\u043e, \u0432\u0430\u0440\u0442\u043e \u043d\u0430\u0432\u0456\u0442\u044c \u043f\u043e\u0448\u0443\u043a\u0430\u0442\u0438 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u044e \u0431\u0456\u0431\u043b\u0456\u043e\u0442\u0435\u043a\u0443 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0432\u0456\u0440\u043a\u0438 \u0434\u0432\u0456\u0439\u043a\u043e\u0432\u0438\u0445 \u0434\u0430\u043d\u0438\u0445 \u043f\u0456\u0441\u043b\u044f \u0457\u0445 \u043e\u0442\u0440\u0438\u043c\u0430\u043d\u043d\u044f. \u0410\u043b\u0435 \u044f \u0432\u0456\u0434\u0432\u043e\u043b\u0456\u043a\u0441\u044f.<\/p>\n<h3>1 \u041f\u0435\u0440\u0435\u0432\u0456\u0440\u0442\u0435 \u043f\u0440\u0430\u0432\u0430 \u043a\u043e\u0440\u0438\u0441\u0442\u0443\u0432\u0430\u0447\u0430<\/h3>\n<p>\u041f\u0430\u043c&#8217;\u044f\u0442\u0430\u0439\u0442\u0435, \u0449\u043e \u0449\u043e\u0440\u0430\u0437\u0443, \u043a\u043e\u043b\u0438 \u043c\u0438 \u0441\u0442\u0432\u043e\u0440\u044e\u0454\u043c\u043e \u0456\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, WordPress \u0433\u0435\u043d\u0435\u0440\u0443\u0454 nonce, \u0449\u043e\u0431 \u043c\u0438 \u043c\u043e\u0433\u043b\u0438 \u0432\u0438\u043a\u043e\u0440\u0438\u0441\u0442\u043e\u0432\u0443\u0432\u0430\u0442\u0438 \u0439\u043e\u0433\u043e, \u0449\u043e\u0431 \u043f\u0435\u0440\u0435\u043a\u043e\u043d\u0430\u0442\u0438\u0441\u044f, \u0449\u043e \u043a\u043e\u0440\u0438\u0441\u0442\u0443\u0432\u0430\u0447 \u043c\u0430\u0454 \u0434\u043e\u0437\u0432\u0456\u043b \u043d\u0430 \u0437\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0435\u043d\u043d\u044f \u0444\u0430\u0439\u043b\u0443.<\/p>\n<p>\u041d\u0430 \u0434\u043e\u0434\u0430\u0442\u043e\u043a \u0434\u043e \u043f\u0435\u0440\u0435\u0432\u0456\u0440\u043a\u0438 nonce, \u0454 \u043a\u0456\u043b\u044c\u043a\u0430 \u0456\u043d\u0448\u0438\u0445 \u0440\u0435\u0447\u0435\u0439, \u044f\u043a\u0456 \u044f \u043b\u044e\u0431\u043b\u044e \u043f\u0435\u0440\u0435\u0432\u0456\u0440\u044f\u0442\u0438, \u0456 \u0432\u0441\u0456 \u0432\u043e\u043d\u0438 \u043c\u0456\u0441\u0442\u044f\u0442\u044c\u0441\u044f \u0432 \u043c\u0435\u0442\u043e\u0434\u0456 \u043f\u0456\u0434 \u043d\u0430\u0437\u0432\u043e\u044e <strong>userCanSave<\/strong>.<\/p>\n<p>\u0421\u043f\u043e\u0447\u0430\u0442\u043a\u0443 <strong><a href=\"https:\/\/gist.github.com\/tommcfarlin\/51b158a2cbc4052bef12cc059837a6ee#file-00-nonce-php\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">\u043f\u0440\u0438\u0433\u0430\u0434\u0430\u0439\u0442\u0435 \u0456\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441:<\/a><\/strong><\/p>\n<pre><code>&lt;form method=\"post\"\n      enctype=\"multipart\/form-data\"\n      action=\"&lt;?php echo esc_html(admin_url('admin-post.php')); ?&gt;\"\"&gt;\n    &lt;!-- Snip For Brevity ---&gt;\n    &lt;?php\n    wp_nonce_field(\n        'acme-item-upload',\n        'acme-item-importer'\n    );\n    ?&gt;\n&lt;\/form&gt;<\/code><\/pre>\n<p>\u0422\u043e\u0434\u0456 \u043f\u043e\u0434\u0438\u0432\u0456\u0442\u044c\u0441\u044f, \u044f\u043a \u044f \u0432\u0438\u043a\u043e\u0440\u0438\u0441\u0442\u043e\u0432\u0443\u044e \u0446\u0435 \u0432 \u043a\u043e\u0434\u0456. \u0421\u043f\u043e\u0447\u0430\u0442\u043a\u0443 \u044f <strong>\u0432\u0438\u0437\u043d\u0430\u0447\u0443 <a href=\"https:\/\/gist.github.com\/tommcfarlin\/51b158a2cbc4052bef12cc059837a6ee#file-01-usercansave-php\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">\u0444\u0443\u043d\u043a\u0446\u0456\u044e<\/a><\/strong> userCanSave :<\/p>\n<pre><code>&lt;?php\n\n\/**\n * Determines if the current user has permission to upload a file based on their current role and the values\n * of the security nonce.\n *\n * @param  string $nonce     The WordPress-generated nonce.\n * @param  string $action    The developer-generated action name.\n * @return bool              True if the user has permission to save; otherwise, false.\n *\/\nprivate function userCanSave($nonce, $action)\n{\n    $isNonceSet   = isset($_POST[$nonce]);\n    $isValidNonce = false;\n\n    if ($isNonceSet) {\n        $isValidNonce = wp_verify_nonce($_POST[$nonce], $action);\n    }\n\n    return ($isNonceSet &amp;&amp; $isValidNonce);\n}\n<\/code><\/pre>\n<p>\u0410 \u043f\u043e\u0442\u0456\u043c \u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0438\u043a\u043b\u0438\u043a\u0430\u044e \u0446\u0435 \u043d\u0430 \u043f\u043e\u0447\u0430\u0442\u043a\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0443. \u042f\u043a\u0449\u043e \u043d\u0435 \u0432\u0434\u0430\u0454\u0442\u044c\u0441\u044f, \u044f <a href=\"https:\/\/gist.github.com\/tommcfarlin\/51b158a2cbc4052bef12cc059837a6ee#file-01-save-part1-php\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">\u043f\u043e\u0432\u0435\u0440\u0442\u0430\u044e\u0441\u044f<\/a>.<\/p>\n<pre><code>&lt;?php\n\n\/**\n * Assuming the user has permission, verifies the security nonce and uploads the PDF file to the `uploads`\n * directory and the Media Library.\n *\/\npublic function save()\n{\n  if (!$this-&gt;userCanSave('acme-item-importer', 'acme-item-upload')) {\n    return;\n  }\n\n  \/\/ More to come...\n\n}\n<\/code><\/pre>\n<p>\u042f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043f\u043e\u043a\u0430\u0437\u0443\u0432\u0430\u0442\u0438 \u043f\u043e\u0432\u0456\u0434\u043e\u043c\u043b\u0435\u043d\u043d\u044f \u043f\u0440\u043e \u043f\u043e\u043c\u0438\u043b\u043a\u0443, \u0430\u043b\u0435 \u044f \u0432\u0456\u0434\u0432\u043e\u043b\u0456\u043a\u0430\u044e\u0441\u044f \u0432\u0456\u0434 \u0446\u044c\u043e\u0433\u043e \u043f\u0438\u0442\u0430\u043d\u043d\u044f, \u043e\u0441\u043a\u0456\u043b\u044c\u043a\u0438 \u0432 \u0434\u043e\u043f\u0438\u0441\u0456 \u0454 \u043a\u0456\u043b\u044c\u043a\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0456\u0432 \u0437\u0440\u043e\u0431\u0438\u0442\u0438 \u0446\u0435.<\/p>\n<h3>2 \u0417\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0442\u0435 \u0444\u0430\u0439\u043b<\/h3>\n<p>\u042f\u043a\u0449\u043e \u043f\u0440\u0438\u043f\u0443\u0441\u0442\u0438\u0442\u0438, \u0449\u043e \u043a\u043e\u0440\u0438\u0441\u0442\u0443\u0432\u0430\u0447 \u043c\u0430\u0454 \u0434\u043e\u0437\u0432\u0456\u043b \u043d\u0430 \u043f\u0435\u0440\u0435\u0432\u0456\u0440\u043a\u0443 \u0444\u0430\u0439\u043b\u0443, \u0442\u043e \u0437\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0438\u0442\u0438 \u0444\u0430\u0439\u043b \u043c\u043e\u0436\u043d\u0430 \u0431\u0435\u0437\u043f\u0435\u0447\u043d\u043e. \u041f\u0440\u043e\u0446\u0435\u0441 \u0432\u0438\u043a\u043e\u043d\u0430\u043d\u043d\u044f \u0446\u044c\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0438\u0439, \u0430\u043b\u0435 \u0432\u0441\u0435 \u043e\u0434\u043d\u043e \u0432\u0438\u043c\u0430\u0433\u0430\u0454 \u0442\u0440\u043e\u0445\u0438 \u0440\u043e\u0431\u043e\u0442\u0438 \u0437 API WordPress (\u0430 \u0441\u0430\u043c\u0435 \u0437 \u0444\u0443\u043d\u043a\u0446\u0456\u0454\u044e <a href=\"https:\/\/codex.wordpress.org\/Function_Reference\/wp_upload_bits\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">wp_upload_bits<\/a> ).<\/p>\n<p>\u0421\u043f\u043e\u0447\u0430\u0442\u043a\u0443 \u0444\u0430\u0439\u043b \u043f\u043e\u0442\u0440\u0456\u0431\u043d\u043e \u043e\u0442\u0440\u0438\u043c\u0430\u0442\u0438 \u0437 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e <a href=\"https:\/\/php.net\/manual\/en\/reserved.variables.files.php\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">$_FILES<\/a> PHP, \u0430 \u043f\u043e\u0442\u0456\u043c \u0437\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0438\u0442\u0438. \u041f\u0440\u043e\u0442\u0435, \u0440\u043e\u0431\u043b\u044f\u0447\u0438 \u0446\u0435, \u0432\u0430\u0436\u043b\u0438\u0432\u043e \u043f\u0435\u0440\u0435\u043a\u043e\u043d\u0430\u0442\u0438\u0441\u044f, \u0449\u043e \u0432\u0438 \u0437\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0443\u0454\u0442\u0435 \u0444\u0430\u0439\u043b \u0456\u0437 <strong><a href=\"https:\/\/gist.github.com\/tommcfarlin\/51b158a2cbc4052bef12cc059837a6ee#file-02-save-part2-php\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0438\u043c \u0440\u043e\u0437\u0448\u0438\u0440\u0435\u043d\u043d\u044f\u043c<\/a><\/strong> (\u043f\u0440\u0438\u043d\u0430\u0439\u043c\u043d\u0456).<\/p>\n<pre><code>&lt;?php\n\n$file_type = explode('.', $filename);\n$file_type = strtolower($file_type[count($file_type) - 1]);\nif ('pdf' !== $file_type) {\n  \/\/ Give your feedback of choice here.\n}\n<\/code><\/pre>\n<p>\u042f\u043a\u0449\u043e \u0442\u0438\u043f \u0444\u0430\u0439\u043b\u0443 \u043d\u0435 \u0454 PDF, \u0432\u0438 \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0438\u043a\u0438\u043d\u0443\u0442\u0438 \u043f\u043e\u0432\u0456\u0434\u043e\u043c\u043b\u0435\u043d\u043d\u044f \u043f\u0440\u043e \u043f\u043e\u043c\u0438\u043b\u043a\u0443, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0432\u0435\u0440\u043d\u0443\u0442\u0438 (\u0445\u043e\u0447\u0430 \u044f \u043d\u0435 \u043f\u0440\u0438\u0445\u0438\u043b\u044c\u043d\u0438\u043a \u0446\u044c\u043e\u0433\u043e) \u0430\u0431\u043e <strong><a href=\"https:\/\/gist.github.com\/tommcfarlin\/51b158a2cbc4052bef12cc059837a6ee#file-03-save-part3-php\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">\u043d\u0430\u0434\u0430\u0442\u0438 \u043a\u043e\u0440\u0438\u0441\u0442\u0443\u0432\u0430\u0447\u0435\u0432\u0456 \u0432\u0456\u0434\u0433\u0443\u043a<\/a><\/strong> (\u044f \u043f\u0440\u0438\u0445\u0438\u043b\u044c\u043d\u0438\u043a \u0446\u044c\u043e\u0433\u043e \u0440\u043e\u0431\u0438\u0442\u0438).<\/p>\n<pre><code>&lt;?php\n\nif ($uploadFile['error']) {\n  \/\/ Your preferred method of feedback here.\n}<\/code><\/pre>\n<p>\u0410\u043b\u0435 \u043e\u0441\u0442\u0430\u043d\u043d\u0456\u043c \u043a\u0440\u043e\u043a\u043e\u043c \u0454 \u200b\u200b\u0437\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0435\u043d\u043d\u044f \u0444\u0430\u0439\u043b\u0443 \u0432 \u043c\u0435\u0434\u0456\u0430-\u0437\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0443\u0432\u0430\u0447.<\/p>\n<h3>3 \u0417\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0435\u043d\u043d\u044f \u0432 \u043c\u0435\u0434\u0456\u0430-\u0437\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0443\u0432\u0430\u0447<\/h3>\n<p>\u041e\u0441\u0442\u0430\u043d\u043d\u0456\u043c \u043a\u0440\u043e\u043a\u043e\u043c \u0443 \u0432\u0441\u044c\u043e\u043c\u0443 \u0446\u044c\u043e\u043c\u0443 \u0454 \u0437\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0435\u043d\u043d\u044f \u0444\u0430\u0439\u043b\u0443 \u0432 \u043c\u0435\u0434\u0456\u0430-\u0437\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0443\u0432\u0430\u0447. \u0414\u043b\u044f \u0446\u044c\u043e\u0433\u043e \u0432\u0430\u043c \u0437\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043a\u0456\u043b\u044c\u043a\u0430 \u0440\u0435\u0447\u0435\u0439 \u0437 \u044f\u0434\u0440\u0430 WordPress:<\/p>\n<ol>\n<li>\u0431\u0456\u0431\u043b\u0456\u043e\u0442\u0435\u043a\u0430 file.php,<\/li>\n<li>\u043c\u0430\u0441\u0438\u0432 \u0432\u043a\u043b\u0430\u0434\u0435\u043d\u044c, \u043d\u0435\u043e\u0431\u0445\u0456\u0434\u043d\u0438\u0439, \u0449\u043e\u0431 \u043f\u043e\u0432\u0456\u0434\u043e\u043c\u043b\u044f\u0442\u0438 WordPress, \u0449\u043e \u0434\u043e\u0434\u0430\u0454\u0442\u044c\u0441\u044f,<\/li>\n<li>\u0444\u0443\u043d\u043a\u0446\u0456\u044f WordPress API, <strong>wp_insert_attachment<\/strong><\/li>\n<li>\u043f\u0435\u0440\u0435\u0441\u043f\u0440\u044f\u043c\u0443\u0432\u0430\u043d\u043d\u044f \u043d\u0430\u0437\u0430\u0434 \u043d\u0430 \u0441\u0442\u043e\u0440\u0456\u043d\u043a\u0443 \u0432\u0438\u043a\u043b\u0438\u043a\u0443<\/li>\n<\/ol>\n<p>\u0417\u0432\u0443\u0447\u0438\u0442\u044c \u0431\u0430\u0433\u0430\u0442\u043e, \u043f\u0440\u0430\u0432\u0434\u0430? \u0426\u0435 \u043d\u0435 \u0442\u0430\u043a \u0432\u0436\u0435 \u0439 \u043f\u043e\u0433\u0430\u043d\u043e.<\/p>\n<p>\u0417\u0430\u0437\u0432\u0438\u0447\u0430\u0439 \u044f \u0433\u0440\u0443\u043f\u0443\u044e \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044f \u0431\u0456\u0431\u043b\u0456\u043e\u0442\u0435\u043a\u0438 \u0444\u0430\u0439\u043b\u0456\u0432 WordPress \u0456 <strong>wp_insert_attachment<\/strong> \u0432 \u043e\u0434\u0438\u043d \u0431\u043b\u043e\u043a.<\/p>\n<p>\u0412\u0438 \u043f\u043e\u043c\u0456\u0442\u0438\u0442\u0435, \u0449\u043e \u044f \u0432\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u044e\u044e \u0442\u0438\u043f MIME \u043d\u0430 <strong>pdf<\/strong> \u0456 \u043f\u0435\u0440\u0435\u043a\u043e\u043d\u0430\u044e\u0441\u044f, \u0449\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043d\u0435 \u043c\u0456\u0441\u0442\u0438\u0442\u044c \u043d\u0456\u0447\u043e\u0433\u043e, \u043a\u0440\u0456\u043c \u043d\u0430\u0437\u0432\u0438 \u0444\u0430\u0439\u043b\u0443. \u041f\u0456\u0441\u043b\u044f \u0446\u044c\u043e\u0433\u043e \u044f \u0432\u0438\u043a\u043e\u0440\u0438\u0441\u0442\u043e\u0432\u0443\u044e <a href=\"https:\/\/codex.wordpress.org\/Function_Reference\/wp_insert_attachment\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">wp_insert_attachment<\/a>, \u0449\u043e\u0431 \u0437\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0438\u0442\u0438 \u0444\u0430\u0439\u043b \u0443 \u043c\u0435\u0434\u0456\u0430\u0442\u0435\u043a\u0443.<\/p>\n<\/p>\n<p>\u041f\u043e\u0432\u043d\u0438\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f \u0446\u044c\u043e\u0433\u043e \u0432\u0438\u0433\u043b\u044f\u0434\u0430\u0454 <strong><a href=\"https:\/\/gist.github.com\/tommcfarlin\/51b158a2cbc4052bef12cc059837a6ee#file-05-save-part5-php\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">\u043d\u0430\u0441\u0442\u0443\u043f\u043d\u0438\u043c \u0447\u0438\u043d\u043e\u043c:<\/a><\/strong><\/p>\n<pre><code>&lt;?php\n\nrequire_once(ABSPATH. \"wp-admin\". '\/includes\/file.php');\n$attachment  = array(\n    'post_mime_type' =&gt; 'pdf',\n    'post_title'     =&gt; preg_replace('\/.[^.]+$\/', '', $filename),\n    'post_status'    =&gt; 'inherit'\n);\n$attachment_id = wp_insert_attachment($attachment, $uploadFile['file']);\n<\/code><\/pre>\n<p>\u041f\u0456\u0441\u043b\u044f \u0446\u044c\u043e\u0433\u043e \u044f \u043f\u043e\u0432\u0435\u0440\u0442\u0430\u044e\u0441\u044f \u043d\u0430 \u0441\u0442\u043e\u0440\u0456\u043d\u043a\u0443, \u0437 \u044f\u043a\u043e\u0457 \u0432\u0441\u0435 \u0446\u0435 \u043f\u043e\u0447\u0430\u043b\u043e\u0441\u044f (\u0437\u0430\u0437\u0432\u0438\u0447\u0430\u0439 \u0446\u0435 \u0441\u0442\u043e\u0440\u0456\u043d\u043a\u0430 \u0430\u0434\u043c\u0456\u043d\u0456\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430, \u044f\u043a\u0443 \u043c\u0438 \u0431\u0430\u0447\u0438\u043b\u0438 \u0432 \u043f\u043e\u043f\u0435\u0440\u0435\u0434\u043d\u0456\u0439 \u043f\u0443\u0431\u043b\u0456\u043a\u0430\u0446\u0456\u0457. \u0414\u043b\u044f \u0446\u044c\u043e\u0433\u043e \u044f <strong>\u0437\u0430\u0431\u0438\u0440\u0430\u044e _wp_http_referer \u0437 \u043c\u0430\u0441\u0438\u0432\u0443<\/strong> <a href=\"https:\/\/php.net\/manual\/en\/reserved.variables.request.php\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">$_REQUEST<\/a> PHP .<\/p>\n<pre><code>&lt;?php\nwp_safe_redirect(\n    $_REQUEST['_wp_http_referer'],\n    301\n);\nexit;\n<\/code><\/pre>\n<p>\u0406 \u0446\u0435 <a href=\"https:\/\/gist.github.com\/tommcfarlin\/51b158a2cbc4052bef12cc059837a6ee#file-06-save-part6-php\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">\u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u0438\u0442\u044c<\/a> \u043a\u043e\u0440\u0438\u0441\u0442\u0443\u0432\u0430\u0447\u0430 \u043d\u0430\u0437\u0430\u0434 \u043d\u0430 \u0441\u0442\u043e\u0440\u0456\u043d\u043a\u0443, \u0437 \u044f\u043a\u043e\u0457 \u0432\u0456\u043d \u043f\u0440\u0438\u0439\u0448\u043e\u0432.<\/p>\n<h2>\u0406 \u0444\u0430\u0439\u043b \u0437\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0435\u043d\u043e<\/h2>\n<p>\u041d\u0430 \u0446\u044c\u043e\u043c\u0443 \u0435\u0442\u0430\u043f\u0456 \u043c\u0438 \u0432\u0438\u0437\u043d\u0430\u0447\u0438\u043b\u0438, \u0449\u043e \u043c\u0438 \u0445\u043e\u0447\u0435\u043c\u043e \u0437\u0440\u043e\u0431\u0438\u0442\u0438:<\/p>\n<ol>\n<li>\u041d\u0430\u0434\u0430\u0439\u0442\u0435 \u0433\u0456\u0434\u043d\u0438\u0439 \u043a\u043b\u0456\u0454\u043d\u0442\u0441\u044c\u043a\u0438\u0439 \u0434\u043e\u0441\u0432\u0456\u0434,<\/li>\n<li>\u0417\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0438\u0432 \u0444\u0430\u0439\u043b \u0434\u043e \u043c\u0435\u0434\u0456\u0430\u0442\u0435\u043a\u0438 (\u0437 \u043c\u043e\u0436\u043b\u0438\u0432\u0456\u0441\u0442\u044e \u0437\u0430\u043f\u0440\u043e\u043f\u043e\u043d\u0443\u0432\u0430\u0442\u0438 \u0432\u0456\u0434\u0433\u0443\u043a)<\/li>\n<li>\u0406 \u043f\u0435\u0440\u0435\u0441\u043f\u0440\u044f\u043c\u0443\u0432\u0430\u0432 \u043d\u0430\u0437\u0430\u0434 \u043d\u0430 \u0441\u0442\u043e\u0440\u0456\u043d\u043a\u0443, \u0437 \u044f\u043a\u043e\u0457 \u0432\u0441\u0435 \u043f\u043e\u0447\u0430\u043b\u043e\u0441\u044f.<\/li>\n<\/ol>\n<p>\u0417\u0432\u0438\u0447\u0430\u0439\u043d\u043e, \u0443 \u0446\u044c\u043e\u043c\u0443 \u0454 \u0431\u0430\u0433\u0430\u0442\u043e \u043c\u0456\u0441\u0446\u044f \u0434\u043b\u044f \u0432\u0456\u0434\u0433\u0443\u043a\u0456\u0432, \u0456 \u044f \u0437\u0430\u043a\u043b\u0438\u043a\u0430\u044e \u0432\u0430\u0441 \u0430\u0434\u0430\u043f\u0442\u0443\u0432\u0430\u0442\u0438 \u0446\u0435 \u0437\u0430 \u043f\u043e\u0442\u0440\u0435\u0431\u0438 \u0434\u043b\u044f \u0441\u0432\u043e\u0433\u043e \u043a\u043e\u0434\u0443, \u0430\u043b\u0435 \u043e\u0441\u043d\u043e\u0432\u0443 \u0442\u043e\u0433\u043e, \u0449\u043e \u0432\u0430\u043c \u043f\u043e\u0442\u0440\u0456\u0431\u043d\u043e, \u0441\u043b\u0456\u0434 \u043d\u0430\u0434\u0430\u0442\u0438 \u044f\u043a <a href=\"https:\/\/wordpress.mediadoma.com\/uk\/zavantazhennja-fajliv-u-wordpress-peregljanuto-chastina-1-storona-kliienta\/\" title=\"\u0443 \u043f\u043e\u043f\u0435\u0440\u0435\u0434\u043d\u0456\u0439\">\u0443 \u043f\u043e\u043f\u0435\u0440\u0435\u0434\u043d\u0456\u0439<\/a>, \u0442\u0430\u043a \u0456 \u0432 \u0446\u0456\u0439 \u043f\u0443\u0431\u043b\u0456\u043a\u0430\u0446\u0456\u0457.<\/p>\n<p><div id=\"PostUnique_PostSource\" style=\"padding-top: 50px\">\u0414\u0436\u0435\u0440\u0435\u043b\u043e \u0437\u0430\u043f\u0438\u0441\u0443:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/tommcfarlin.com\" class=\"external external_icon\">tommcfarlin.com<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u0440\u0438\u043a\u043b\u0430\u0434 \u043a\u043e\u0434\u0443 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0456 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043d\u0435\u043e\u0431\u0445\u0456\u0434\u043d\u043e\u0433\u043e \u0434\u043b\u044f \u0437\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0435\u043d\u043d\u044f \u0444\u0430\u0439\u043b\u0443 \u0447\u0435\u0440\u0435\u0437 WordPress (\u0456 Media Uploader).<\/p>\n","protected":false},"author":1,"featured_media":164785,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[869,902,849],"tags":[1174],"class_list":["post-230005","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress-10","category-kod-3","category-pidruchnyky","tag-affiai-uk"],"_links":{"self":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/posts\/230005","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/comments?post=230005"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/posts\/230005\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/media\/164785"}],"wp:attachment":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/media?parent=230005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/categories?post=230005"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/tags?post=230005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}