{"id":3224,"date":"2020-07-10T17:53:35","date_gmt":"2020-07-10T08:53:35","guid":{"rendered":"https:\/\/taitan916.info\/blog\/?p=3224"},"modified":"2024-01-16T18:09:01","modified_gmt":"2024-01-16T09:09:01","slug":"post-3224","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/3224","title":{"rendered":"PHP\u3092\u7528\u3044\u3066\u30d5\u30a9\u30fc\u30e0\u304b\u3089zip\u30d5\u30a1\u30a4\u30eb\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u30b5\u30fc\u30d0\u4e0a\u3067\u89e3\u51cd(\u5c55\u958b)\u3055\u305b\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>form\u304b\u3089zip\u30d5\u30a1\u30a4\u30eb\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u30b5\u30fc\u30d0\u4e0a\u3067\u89e3\u51cd(\u5c55\u958b)\u3059\u308b\u3068\u3044\u3046\u4e00\u9023\u306e\u51e6\u7406\u3092PHP\u3067\u884c\u3044\u305f\u3044\u3002\u307e\u305f\u3001\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u305fzip\u30d5\u30a1\u30a4\u30eb\u306f\u524a\u9664\u3001\u89e3\u51cd\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u306f\u540c\u540d\u306b\u306a\u3089\u306a\u3044\u3088\u3046\u6307\u5b9a\u3057\u305f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u5185\u306b\u5c55\u958b\u3057\u305f\u3044\u3002\u4ee5\u4e0b\u306b\u5b9f\u88c5\u65b9\u6cd5\u3092\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>HTML\u90e8\u5206<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;form action=\"&lt;?php echo $_SERVER['PHP_SELF'];?&gt;\" method=\"POST\" enctype=\"multipart\/form-data\"&gt;\r\n    &lt;input type=\"file\" name=\"zip\"&gt;\r\n    &lt;input type=\"submit\"&gt;\r\n&lt;\/form&gt;<\/pre>\n<p>&nbsp;<\/p>\n<h2>PHP\u90e8\u5206<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?php\r\n$dir = __DIR__ . '\/';\r\n\r\n\/\/\u30d5\u30a1\u30a4\u30eb\u304c\u9001\u4fe1\u3055\u308c\u305f\u5834\u5408\r\nif( $_FILES['zip']['size'] &gt; 0 ){\r\n\r\n    $zip_name = md5(uniqid(rand(), true)) . '_' . time();\r\n    $zip_file = $zip_name . '.zip';\r\n\r\n    \/\/\u30b5\u30fc\u30d0\u306b\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\r\n    if( move_uploaded_file($_FILES['zip']['tmp_name'], $dir . $zip_file) ){\r\n\r\n        $zip = new ZipArchive;\r\n        if($zip-&gt;open($zip_file) === TRUE){\r\n            $zip-&gt;extractTo($dir . $zip_name);\r\n            $zip-&gt;close();\r\n\r\n            echo 'OK';\r\n\r\n            \/\/zip\u30d5\u30a1\u30a4\u30eb\u306e\u524a\u9664\r\n            unlink($zip_file);\r\n\r\n            \/\/\u5c55\u958b\u3055\u308c\u305f\u30d5\u30a9\u30eb\u30c0\u5185\u306b\u3042\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u691c\u7d22\r\n            $dirs = scandir($dir . $zip_name . '\/');\r\n\r\n            \/\/\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u6c7a\u3081\u6253\u3061(0-&gt;'.', 1-&gt;'..'\u306b\u306a\u308b)\r\n            $tmp_dir = $dir . $zip_name . '\/' .  $dirs[2] . '\/*';\r\n\r\n            foreach(glob($tmp_dir) as $file){\r\n                if(is_file($file)){\r\n                    var_dump($file);\r\n                }\r\n            }\r\n\r\n        }else{\r\n            echo '\u89e3\u51cd\u30a8\u30e9\u30fc';\r\n        }\r\n\r\n    }else{\r\n        echo '\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u30a8\u30e9\u30fc';\r\n    }\r\n\r\n}\r\n?&gt;<\/pre>\n<p>\u57fa\u672c\u7684\u306b\u306f\u30b3\u30e1\u30f3\u30c8\u306e\u901a\u308a\u3060\u304c\u30d5\u30a1\u30a4\u30eb\u304c\u9001\u4fe1\u3055\u308c\u305f\u5834\u5408\u306b\u30b5\u30fc\u30d0\u306b\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u3001zip\u30d5\u30a1\u30a4\u30eb\u3092\u89e3\u51cd\u3002\u305d\u306e\u5f8c\u3001zip\u30d5\u30a1\u30a4\u30eb\u306f\u524a\u9664\u3057\u6307\u5b9a\u3057\u305f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u5185\u306b\u5c55\u958b\u3059\u308b\u3002\u5c55\u958b\u3057\u305f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u5185\u306b\u3042\u308b\u30d5\u30a1\u30a4\u30eb\u3092\u691c\u7d22\u3057\u3001var_dump\u3067\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u51fa\u529b\u3059\u308b\u3002<\/p>\n<p>\u307e\u305f\u3001<a href=\"https:\/\/www.php.net\/manual\/ja\/class.ziparchive.php\" target=\"_blank\" rel=\"noopener\">ZipArchve\u30af\u30e9\u30b9\u306b\u95a2\u3057\u3066\u306f\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u3092\u53c2\u7167<\/a>\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u6ce8\u610f\u70b9<\/h2>\n<h3>\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba\u306b\u6ce8\u610f\u3059\u308b<\/h3>\n<p>zip\u30d5\u30a1\u30a4\u30eb\u3067\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u306e\u3067zip\u5185\u306b\u8907\u6570\u306e\u30d5\u30a1\u30a4\u30eb\u304c\u5165\u3063\u3066\u3044\u308b\u30b1\u30fc\u30b9\u304c\u591a\u3044\u3068\u601d\u308f\u308c\u3001\u7d50\u679c\u3068\u3057\u3066\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba\u304c\u5927\u304d\u304f\u306a\u308a\u305d\u3046\u3002<\/p>\n<p>\u306a\u306e\u3067php.ini\u5074\u306e\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u30b5\u30a4\u30ba\u4e0a\u9650\u3084\u30b5\u30fc\u30d0\u5074\u306eHDD\u3082\u3057\u304f\u306fSSD\u5bb9\u91cf\u306b\u6ce8\u610f\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<\/p>\n<h3>zip\u5074\u3067\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u6c7a\u3081\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308b<\/h3>\n<p>\u4eca\u56de\u306f\u3068\u308a\u3042\u3048\u305aPHP\u3067zip\u89e3\u51cd\u3059\u308b\u3068\u3053\u308d\u307e\u3067\u691c\u8a3c\u3057\u305f\u304b\u3063\u305f\u306e\u3067\u3001\u9069\u5f53\u306a\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u30d5\u30a9\u30eb\u30c0\u306b\u7a81\u3063\u8fbc\u307f\u3001\u305d\u306e\u30d5\u30a9\u30eb\u30c0\u3092zip\u5727\u7e2e\u3057\u305f\u3002\u3053\u308c\u304c\u4f8b\u3048\u3070\u591a\u91cd\u69cb\u9020\u306e\u30d5\u30a9\u30eb\u30c0\u306b\u306a\u3063\u3066\u3044\u305f\u308a\u3059\u308b\u3068\u51e6\u7406\u304c\u975e\u5e38\u306b\u9762\u5012\u304f\u3055\u305d\u3046\u3002<\/p>\n<p>\u306a\u306e\u3067\u591a\u91cd\u69cb\u9020\u306f\u7981\u6b62\u3060\u3068\u304b\u3001\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u5074\u306b\u3082\u3042\u308b\u7a0b\u5ea6\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u6c7a\u3081\u3066\u304a\u304f\u5fc5\u8981\u3042\u308a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>form\u304b\u3089zip\u30d5\u30a1\u30a4\u30eb\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u30b5\u30fc\u30d0\u4e0a\u3067\u89e3\u51cd(\u5c55\u958b)\u3059\u308b\u3068\u3044\u3046\u4e00\u9023\u306e ... <\/p>\n","protected":false},"author":1,"featured_media":1085,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-3224","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/3224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/comments?post=3224"}],"version-history":[{"count":0,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/3224\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media\/1085"}],"wp:attachment":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media?parent=3224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=3224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=3224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}