{"id":747,"date":"2024-04-19T17:28:48","date_gmt":"2024-04-19T16:28:48","guid":{"rendered":"https:\/\/itsiller-software.com\/?page_id=747"},"modified":"2024-04-19T17:29:23","modified_gmt":"2024-04-19T16:29:23","slug":"9-2","status":"publish","type":"page","link":"https:\/\/itsiller-software.com\/index.php\/9-2\/","title":{"rendered":"9"},"content":{"rendered":"<div><?php\n\/\/ 1. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043c\u0435\u0434\u0438\u0430\u0444\u0430\u0439\u043b\u043e\u0432\nfunction process_media_upload() {\n  \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 nonce \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438\n\n  \/\/ \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b\n  $uploaded_file = $_FILES['file'];\n\n  \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0442\u0438\u043f\u0430 \u0444\u0430\u0439\u043b\u0430 \u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u0430\n  if ($uploaded_file['error'] === UPLOAD_ERR_OK) {\n    $file_type = $uploaded_file['type'];\n    $file_size = $uploaded_file['size'];\n\n    if (in_array($file_type, ['audio\/mpeg', 'video\/mp4', 'image\/*'])) {\n      if ($file_size <= 1024000) { \/\/ 1 \u041c\u0411\n        \/\/ \u041f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0444\u0430\u0439\u043b \u0432 \u043f\u0430\u043f\u043a\u0443 \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438\n        $file_path = move_uploaded_file($uploaded_file['tmp_name'], wp_upload_dir()['basedir'] . '\/' . $uploaded_file['name']);\n\n        if ($file_path) {\n          \/\/ \u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0444\u0430\u0439\u043b\u0435 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445\n          global $wpdb;\n          $table_name = $wpdb->prefix . &#8216;media_uploads&#8217;; \/\/ \u0418\u043c\u044f \u0432\u0430\u0448\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432 \u0411\u0414<\/p>\n<p>          $wpdb->insert($table_name, [<br \/>\n            &#8216;file_name&#8217; => $uploaded_file[&#8216;name&#8217;],<br \/>\n            &#8216;file_type&#8217; => $file_type,<br \/>\n            &#8216;file_path&#8217; => $file_path,<br \/>\n          ]);<\/p>\n<p>          \/\/ \u0412\u044b\u0432\u0435\u0441\u0442\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435<br \/>\n          echo &#8216;\u0424\u0430\u0439\u043b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d!&#8217;;<br \/>\n        } else {<br \/>\n          \/\/ \u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0438 \u0444\u0430\u0439\u043b\u0430<br \/>\n          echo &#8216;\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0438 \u0444\u0430\u0439\u043b\u0430.&#8217;;<br \/>\n        }<br \/>\n      } else {<br \/>\n        \/\/ \u0424\u0430\u0439\u043b \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0439<br \/>\n        echo &#8216;\u0424\u0430\u0439\u043b \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 1 \u041c\u0411.&#8217;;<br \/>\n      }<br \/>\n    } else {<br \/>\n      \/\/ \u041d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 \u0442\u0438\u043f \u0444\u0430\u0439\u043b\u0430<br \/>\n      echo &#8216;\u041d\u0435\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0439 \u0442\u0438\u043f \u0444\u0430\u0439\u043b\u0430.&#8217;;<br \/>\n    }<br \/>\n  } else {<br \/>\n    \/\/ \u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0444\u0430\u0439\u043b\u0430<br \/>\n    echo &#8216;\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0444\u0430\u0439\u043b\u0430.&#8217;;<br \/>\n  }<br \/>\n}<\/p>\n<p>\/\/ 2. \u0428\u043e\u0440\u0442\u043a\u043e\u0434 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0445 \u043c\u0435\u0434\u0438\u0430\u0444\u0430\u0439\u043b\u043e\u0432<br \/>\nfunction display_media_uploads($atts) {<br \/>\n  global $wpdb;<br \/>\n  $table_name = $wpdb->prefix . &#8216;media_uploads&#8217;; \/\/ \u0418\u043c\u044f \u0432\u0430\u0448\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432 \u0411\u0414<\/p>\n<p>  $media_items = $wpdb->get_results(&#8220;SELECT * FROM $table_name&#8221;);<\/p>\n<p>  if ($media_items) {<br \/>\n    $output = &#8221;;<br \/>\n    foreach ($media_items as $item) {<br \/>\n      $file_type = $item->file_type;<br \/>\n      $file_path = $item->file_path;<\/p>\n<p>      switch ($file_type) {<br \/>\n        case &#8216;audio\/mpeg&#8217;:<br \/>\n          $output .= &#8216;<audio src=\"' . $file_path . '\" controls><\/audio>&#8216;;<br \/>\n          break;<br \/>\n        case &#8216;video\/mp4&#8217;:<br \/>\n          $output .= &#8216;<video src=\"' . $file_path . '\" controls><\/video>&#8216;;<br \/>\n          break;<br \/>\n        default:<br \/>\n          $output .= &#8216;<img decoding=\"async\" src=\"' . $file_path . '\" alt=\"' . $item->file_name . &#8216;&#8221;>&#8217;;<br \/>\n      }<br \/>\n    }<br \/>\n    return $output;<br \/>\n  } else {<br \/>\n    return &#8216;\u0417\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 \u043d\u0435\u0442.&#8217;;<br \/>\n  }<br \/>\n}<\/p>\n<p>add_shortcode(&#8216;media_uploads&#8217;, &#8216;display_media_uploads&#8217;);<\/p>\n<p>\/\/ 3. \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0444\u043e\u0440\u043c\u044b \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0432 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443<br \/>\n?><\/p>\n<form method=\"post\" enctype=\"multipart\/form-data\">\n<div class=\"uk-margin\" uk-margin>\n<div uk-form-custom=\"target: true\">\n      <input type=\"file\" name=\"file\" aria-label=\"Custom controls\" accept=\".mp3,.mp4,image\/*\"><br \/>\n      <input class=\"uk-input uk-form-width-medium\" type=\"text\" placeholder=\"Select file\" aria-label=\"Custom controls\" disabled>\n    <\/div>\n<p>    <button class=\"uk-button uk-button-default\" type=\"submit\">Submit<\/button>\n  <\/div>\n<\/form>\n<p><?php\n\n\/\/ 4. \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0444\u043e\u0440\u043c\u044b \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435\nif (isset($_POST['\n<\/div>\n<p><!--more--><br \/>\n<!-- {\"type\":\"layout\",\"children\":[{\"type\":\"section\",\"props\":{\"image_position\":\"center-center\",\"style\":\"default\",\"title_breakpoint\":\"xl\",\"title_position\":\"top-left\",\"title_rotation\":\"left\",\"vertical_align\":\"middle\",\"width\":\"default\"},\"children\":[{\"type\":\"row\",\"children\":[{\"type\":\"column\",\"props\":{\"image_position\":\"center-center\",\"position_sticky_breakpoint\":\"m\"},\"children\":[{\"type\":\"text\",\"props\":{\"column_breakpoint\":\"m\",\"content\":\"<?php\\n\\\/\\\/ 1. \\u0424\\u0443\\u043d\\u043a\\u0446\\u0438\\u044f \\u043e\\u0431\\u0440\\u0430\\u0431\\u043e\\u0442\\u043a\\u0438 \\u0437\\u0430\\u0433\\u0440\\u0443\\u0437\\u043a\\u0438 \\u043c\\u0435\\u0434\\u0438\\u0430\\u0444\\u0430\\u0439\\u043b\\u043e\\u0432\\nfunction process_media_upload() {\\n  \\\/\\\/ \\u041f\\u0440\\u043e\\u0432\\u0435\\u0440\\u043a\\u0430 nonce \\u0438 \\u0434\\u0440\\u0443\\u0433\\u0438\\u0445 \\u043f\\u0430\\u0440\\u0430\\u043c\\u0435\\u0442\\u0440\\u043e\\u0432 \\u0431\\u0435\\u0437\\u043e\\u043f\\u0430\\u0441\\u043d\\u043e\\u0441\\u0442\\u0438\\n\\n  \\\/\\\/ \\u041f\\u043e\\u043b\\u0443\\u0447\\u0438\\u0442\\u044c \\u0437\\u0430\\u0433\\u0440\\u0443\\u0436\\u0435\\u043d\\u043d\\u044b\\u0439 \\u0444\\u0430\\u0439\\u043b\\n  $uploaded_file = $_FILES['file'];\\n\\n  \\\/\\\/ \\u041f\\u0440\\u043e\\u0432\\u0435\\u0440\\u043a\\u0430 \\u0442\\u0438\\u043f\\u0430 \\u0444\\u0430\\u0439\\u043b\\u0430 \\u0438 \\u0440\\u0430\\u0437\\u043c\\u0435\\u0440\\u0430\\n  if ($uploaded_file['error'] === UPLOAD_ERR_OK) {\\n    $file_type = $uploaded_file['type'];\\n    $file_size = $uploaded_file['size'];\\n\\n    if (in_array($file_type, ['audio\\\/mpeg', 'video\\\/mp4', 'image\\\/*'])) {\\n      if ($file_size <= 1024000) { \\\/\\\/ 1 \\u041c\\u0411\\n        \\\/\\\/ \\u041f\\u0435\\u0440\\u0435\\u043c\\u0435\\u0441\\u0442\\u0438\\u0442\\u044c \\u0444\\u0430\\u0439\\u043b \\u0432 \\u043f\\u0430\\u043f\\u043a\\u0443 \\u0434\\u043b\\u044f \\u0437\\u0430\\u0433\\u0440\\u0443\\u0437\\u043a\\u0438\\n        $file_path = move_uploaded_file($uploaded_file['tmp_name'], wp_upload_dir()['basedir'] . '\\\/' . $uploaded_file['name']);\\n\\n        if ($file_path) {\\n          \\\/\\\/ \\u0421\\u043e\\u0445\\u0440\\u0430\\u043d\\u0438\\u0442\\u044c \\u0438\\u043d\\u0444\\u043e\\u0440\\u043c\\u0430\\u0446\\u0438\\u044e \\u043e \\u0444\\u0430\\u0439\\u043b\\u0435 \\u0432 \\u0431\\u0430\\u0437\\u0435 \\u0434\\u0430\\u043d\\u043d\\u044b\\u0445\\n          global $wpdb;\\n          $table_name = $wpdb->prefix . 'media_uploads'; \\\/\\\/ \\u0418\\u043c\\u044f \\u0432\\u0430\\u0448\\u0435\\u0439 \\u0442\\u0430\\u0431\\u043b\\u0438\\u0446\\u044b \\u0432 \\u0411\\u0414\\n\\n          $wpdb->insert($table_name, [\\n            'file_name' => $uploaded_file['name'],\\n            'file_type' => $file_type,\\n            'file_path' => $file_path,\\n          ]);\\n\\n          \\\/\\\/ \\u0412\\u044b\\u0432\\u0435\\u0441\\u0442\\u0438 \\u0441\\u043e\\u043e\\u0431\\u0449\\u0435\\u043d\\u0438\\u0435 \\u043e\\u0431 \\u0443\\u0441\\u043f\\u0435\\u0448\\u043d\\u043e\\u0439 \\u0437\\u0430\\u0433\\u0440\\u0443\\u0437\\u043a\\u0435\\n          echo '\\u0424\\u0430\\u0439\\u043b \\u0443\\u0441\\u043f\\u0435\\u0448\\u043d\\u043e \\u0437\\u0430\\u0433\\u0440\\u0443\\u0436\\u0435\\u043d!';\\n        } else {\\n          \\\/\\\/ \\u041e\\u0448\\u0438\\u0431\\u043a\\u0430 \\u043f\\u0440\\u0438 \\u043f\\u0435\\u0440\\u0435\\u043c\\u0435\\u0449\\u0435\\u043d\\u0438\\u0438 \\u0444\\u0430\\u0439\\u043b\\u0430\\n          echo '\\u041e\\u0448\\u0438\\u0431\\u043a\\u0430 \\u043f\\u0440\\u0438 \\u043f\\u0435\\u0440\\u0435\\u043c\\u0435\\u0449\\u0435\\u043d\\u0438\\u0438 \\u0444\\u0430\\u0439\\u043b\\u0430.';\\n        }\\n      } else {\\n        \\\/\\\/ \\u0424\\u0430\\u0439\\u043b \\u0441\\u043b\\u0438\\u0448\\u043a\\u043e\\u043c \\u0431\\u043e\\u043b\\u044c\\u0448\\u043e\\u0439\\n        echo '\\u0424\\u0430\\u0439\\u043b \\u0434\\u043e\\u043b\\u0436\\u0435\\u043d \\u0431\\u044b\\u0442\\u044c \\u043d\\u0435 \\u0431\\u043e\\u043b\\u0435\\u0435 1 \\u041c\\u0411.';\\n      }\\n    } else {\\n      \\\/\\\/ \\u041d\\u0435\\u0432\\u0435\\u0440\\u043d\\u044b\\u0439 \\u0442\\u0438\\u043f \\u0444\\u0430\\u0439\\u043b\\u0430\\n      echo '\\u041d\\u0435\\u0434\\u043e\\u043f\\u0443\\u0441\\u0442\\u0438\\u043c\\u044b\\u0439 \\u0442\\u0438\\u043f \\u0444\\u0430\\u0439\\u043b\\u0430.';\\n    }\\n  } else {\\n    \\\/\\\/ \\u041e\\u0448\\u0438\\u0431\\u043a\\u0430 \\u043f\\u0440\\u0438 \\u0437\\u0430\\u0433\\u0440\\u0443\\u0437\\u043a\\u0435 \\u0444\\u0430\\u0439\\u043b\\u0430\\n    echo '\\u041e\\u0448\\u0438\\u0431\\u043a\\u0430 \\u043f\\u0440\\u0438 \\u0437\\u0430\\u0433\\u0440\\u0443\\u0437\\u043a\\u0435 \\u0444\\u0430\\u0439\\u043b\\u0430.';\\n  }\\n}\\n\\n\\\/\\\/ 2. \\u0428\\u043e\\u0440\\u0442\\u043a\\u043e\\u0434 \\u0434\\u043b\\u044f \\u043e\\u0442\\u043e\\u0431\\u0440\\u0430\\u0436\\u0435\\u043d\\u0438\\u044f \\u0437\\u0430\\u0433\\u0440\\u0443\\u0436\\u0435\\u043d\\u043d\\u044b\\u0445 \\u043c\\u0435\\u0434\\u0438\\u0430\\u0444\\u0430\\u0439\\u043b\\u043e\\u0432\\nfunction display_media_uploads($atts) {\\n  global $wpdb;\\n  $table_name = $wpdb->prefix . 'media_uploads'; \\\/\\\/ \\u0418\\u043c\\u044f \\u0432\\u0430\\u0448\\u0435\\u0439 \\u0442\\u0430\\u0431\\u043b\\u0438\\u0446\\u044b \\u0432 \\u0411\\u0414\\n\\n  $media_items = $wpdb->get_results(\\\"SELECT * FROM $table_name\\\");\\n\\n  if ($media_items) {\\n    $output = '';\\n    foreach ($media_items as $item) {\\n      $file_type = $item->file_type;\\n      $file_path = $item->file_path;\\n\\n      switch ($file_type) {\\n        case 'audio\\\/mpeg':\\n          $output .= '<audio src=\\\"' . $file_path . '\\\" controls><\\\/audio>';\\n          break;\\n        case 'video\\\/mp4':\\n          $output .= '<video src=\\\"' . $file_path . '\\\" controls><\\\/video>';\\n          break;\\n        default:\\n          $output .= '<img src=\\\"' . $file_path . '\\\" alt=\\\"' . $item->file_name . '\\\">';\\n      }\\n    }\\n    return $output;\\n  } else {\\n    return '\\u0417\\u0430\\u0433\\u0440\\u0443\\u0436\\u0435\\u043d\\u043d\\u044b\\u0445 \\u0444\\u0430\\u0439\\u043b\\u043e\\u0432 \\u043d\\u0435\\u0442.';\\n  }\\n}\\n\\nadd_shortcode('media_uploads', 'display_media_uploads');\\n\\n\\\/\\\/ 3. \\u0414\\u043e\\u0431\\u0430\\u0432\\u043b\\u0435\\u043d\\u0438\\u0435 \\u0444\\u043e\\u0440\\u043c\\u044b \\u0437\\u0430\\u0433\\u0440\\u0443\\u0437\\u043a\\u0438 \\u0432 \\u0441\\u0442\\u0440\\u0430\\u043d\\u0438\\u0446\\u0443\\n?>\\n\\n\n\n<form method=\\\"post\\\" enctype=\\\"multipart\\\/form-data\\\">\\n  \n\n<div class=\\\"uk-margin\\\" uk-margin>\\n    \n\n<div uk-form-custom=\\\"target: true\\\">\\n      <input type=\\\"file\\\" name=\\\"file\\\" aria-label=\\\"Custom controls\\\" accept=\\\".mp3,.mp4,image\\\/*\\\">\\n      <input class=\\\"uk-input uk-form-width-medium\\\" type=\\\"text\\\" placeholder=\\\"Select file\\\" aria-label=\\\"Custom controls\\\" disabled>\\n    <\\\/div>\\n    <button class=\\\"uk-button uk-button-default\\\" type=\\\"submit\\\">Submit<\\\/button>\\n  <\\\/div>\\n<\\\/form>\\n\\n<?php\\n\\n\\\/\\\/ 4. \\u041e\\u0431\\u0440\\u0430\\u0431\\u043e\\u0442\\u043a\\u0430 \\u0444\\u043e\\u0440\\u043c\\u044b \\u043f\\u0440\\u0438 \\u043e\\u0442\\u043f\\u0440\\u0430\\u0432\\u043a\\u0435\\nif (isset($_POST['\\n\",\"margin\":\"default\"}}]}]}]}],\"version\":\"4.3.8\"} --><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-747","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/itsiller-software.com\/index.php\/wp-json\/wp\/v2\/pages\/747","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itsiller-software.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/itsiller-software.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/itsiller-software.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itsiller-software.com\/index.php\/wp-json\/wp\/v2\/comments?post=747"}],"version-history":[{"count":2,"href":"https:\/\/itsiller-software.com\/index.php\/wp-json\/wp\/v2\/pages\/747\/revisions"}],"predecessor-version":[{"id":750,"href":"https:\/\/itsiller-software.com\/index.php\/wp-json\/wp\/v2\/pages\/747\/revisions\/750"}],"wp:attachment":[{"href":"https:\/\/itsiller-software.com\/index.php\/wp-json\/wp\/v2\/media?parent=747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}