{"id":1488,"date":"2023-05-08T18:42:20","date_gmt":"2023-05-08T10:42:20","guid":{"rendered":"https:\/\/www.yimenapp.cn\/yun\/?p=1488"},"modified":"2023-05-08T18:42:20","modified_gmt":"2023-05-08T10:42:20","slug":"app%e5%9c%a8%e7%ba%bf%e6%89%93%e5%8c%85%e5%b0%81%e8%a3%85%e7%94%9f%e6%88%90%e6%ba%90%e7%a0%81php%e5%8f%af%e4%bb%a5%e5%98%9b%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yimenapp.cn\/yun\/2023\/1488\/","title":{"rendered":"app\u5728\u7ebf\u6253\u5305\u5c01\u88c5\u751f\u6210\u6e90\u7801php\u53ef\u4ee5\u561b\uff1f"},"content":{"rendered":"<p>\u5728\u8fd9\u7bc7\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u8ba8\u8bba\u5982\u4f55\u4f7f\u7528 PHP \u8fdb\u884c\u5728\u7ebf\u6253\u5305\u548c\u5c01\u88c5\u5e94\u7528\u7a0b\u5e8f\uff08app\uff09\u3002\u5728\u7ebf\u6253\u5305\u6307\u7684\u662f\u5c06\u6e90\u4ee3\u7801\u5c01\u88c5\u5230\u4e00\u4e2a\u53ef\u6267\u884c\u7684\u7a0b\u5e8f\u4e2d\uff0c\u800c\u975e\u8ba9\u7528\u6237\u4ece\u6e90\u4ee3\u7801\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u3002\u8fd9\u79cd\u5728\u7ebf\u6253\u5305\u548c\u5c01\u88c5\u7684\u65b9\u6cd5\u5141\u8bb8\u5f00\u53d1\u8005\u5206\u53d1\u5e94\u7528\u7a0b\u5e8f\uff0c\u7528\u6237\u53ef\u4ee5\u4e0d\u4e86\u89e3\u5e95\u5c42\u4ee3\u7801\uff0c\u7b80\u5355\u5730\u4e0b\u8f7d\u548c\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5728\u7ebf\u6253\u5305\u548c\u5c01\u88c5\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u672c\u6982\u5ff5\u548c\u6b65\u9aa4\u3002<\/p>\n<p>1. \u524d\u7f6e\u6761\u4ef6\uff1a<\/p>\n<p>   \u5728\u7ee7\u7eed\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u60a8\u5df2\u5177\u5907\u4ee5\u4e0b\u76f8\u5173\u77e5\u8bc6\u548c\u6280\u80fd\uff1a<\/p>\n<p>   &#8211; \u57fa\u672c\u7684 PHP \u7f16\u7a0b\u77e5\u8bc6\u3002<\/p>\n<p>   &#8211; Web \u670d\u52a1\u5668\uff08\u5982 Apache \u6216 Nginx\uff09\u548c PHP \u73af\u5883\u3002<\/p>\n<p>2. \u57fa\u672c\u539f\u7406\uff1a<\/p>\n<p>   \u5728\u7ebf\u6253\u5305\u548c\u5c01\u88c5\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u672c\u539f\u7406\u662f\uff0c\u5c06\u7528\u6237\u4e0a\u4f20\u7684\u6e90\u4ee3\u7801 zip \u538b\u7f29\u6587\u4ef6\u89e3\u538b\u7f29\u5230\u6307\u5b9a\u7684\u4e34\u65f6\u6587\u4ef6\u5939\uff0c\u7136\u540e\u6267\u884c\u4e00\u7cfb\u5217\u64cd\u4f5c\u6765\u751f\u6210\u5e94\u7528\u7a0b\u5e8f\u6e90\u7801\uff0c\u6700<a href=\"http:\/\/www.yimenyun.cn\/app-shengcheng-gongju-315.html\">\u5c06\u624b\u673a\u7f51\u7ad9\u751f\u6210app<\/a>\u540e\u5c06\u751f\u6210\u7684\u6e90\u7801\u91cd\u65b0\u6253\u5305\u6210\u4e00\u4e2a\u65b0\u7684 zip \u6587\u4ef6\uff0c\u4f9b\u7528\u6237\u4e0b\u8f7d\u3002<\/p>\n<p>3. \u5f00\u59cb\u5b9e\u73b0\u5728\u7ebf\u6253\u5305\u5c01\u88c5\uff1a<\/p>\n<p>   \u4e0b\u9762\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 PHP \u8fdb\u884c\u5728\u7ebf\u6253\u5305\u548c\u5c01\u88c5\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>   a) \u521b\u5efa\u4e00\u4e2a HTML \u8868\u5355\uff0c\u7528\u6237\u63d0\u4ea4\u4e0a\u4f20\u6e90\u4ee3\u7801 zip \u6587\u4ef6\u3002<\/p>\n<p>&#8220;`html<\/p>\n<p>\n<p>\n<p> <title>\u5728\u7ebf\u6253\u5305\u5c01\u88c5<\/title><\/p>\n<\/p>\n<p>\n<p> \u5728\u7ebf\u6253\u5305\u5c01\u88c5<\/p>\n<\/p>\n<p>   <label for=\"file\">\u9009\u62e9\u6e90\u4ee3\u7801 ZIP \u6587\u4ef6\uff1a<\/label><\/p>\n<\/p>\n<\/p>\n<\/p>\n<p>&#8220;`<\/p>\n<p>   b) \u521b\u5efa PHP \u811a\u672c\u6765\u5904\u7406\u4e0a\u4f20\u7684\u6e90\u4ee3\u7801 zip \u6587\u4ef6\u3002<\/p>\n<p>   &#8211; \u63d0\u53d6\u4e0a\u4f20\u7684 zip \u6587\u4ef6\u5230\u4e34\u65f6\u6587\u4ef6\u5939\u3002<\/p>\n<p>   &#8211; \u5728\u4e34\u65f6\u6587\u4ef6\u5939\u4e2d\u6267\u884c\u7a0b\u5e8f\u5c01\u88c5\u64cd\u4f5c\u3002<\/p>\n<p>   &#8211; \u5c01\u88c5\u7a0b\u5e8f\u6e90\u7801\u5230\u4e00\u4e2a\u65b0\u7684 zip \u6587\u4ef6\u3002<\/p>\n<p>&#8220;`php<\/p>\n<\/p>\n<p>\/\/ \u8bbe\u7f6e\u65f6\u533a<\/p>\n<p>date_default_timezone_set(&#8216;Asia\/Shanghai&#8217;);<\/p>\n<p>if ($_FILES[&#8220;file&#8221;][&#8220;error&#8221;] &gt; 0) {<\/p>\n<p>    echo &#8220;Error: &#8221; . $_FILES[&#8220;file&#8221;][&#8220;error&#8221;] . &#8220;<br \/>&#8220;;<\/p>\n<p>} else {<\/p>\n<p>    $tempFilename = $_FILES[&#8220;file&#8221;][&#8220;tmp_name&#8221;];<\/p>\n<p>    $temporaryDir = &#8216;tmp\/&#8217; . <\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.cdn.yimenapp.com\/2023-01\/06\/12\/13490531262.jpg\" \/><\/figure>\n<\/p>\n<p>date(&#8216;YmdHis&#8217;);<\/p>\n<p>    \/\/ \u89e3\u538b\u7f29 zip \u6587\u4ef6<\/p>\n<p>    unzipFile($tempFilename, $temporaryDir);<\/p>\n<p>    \/\/ \u5728\u8fd9\u91cc\u5bf9\u6e90\u4ee3\u7801\u8fdb\u884c\u5c01\u88c5\u64cd\u4f5c\u3002<\/p>\n<p>    \/\/ \u8fd9\u53ef\u80fd\u5305\u62ec\u6dfb\u52a0\u5305\u88c5\u5668\u811a\u672c\u51b3\u5b9a\u518d\u5904\u7406<\/p>\n<p>    \/\/ \u533a\u5206\u662fweb\u7aef\u8fd8\u662fapp\u7aef\u3002\u60a8\u53ef\u4ee5\u6839\u636e\u9700\u8981\u6269\u5c55\u5c01\u88c5\u529f\u80fd\u3002<\/p>\n<p>    \/\/ \u521b\u5efa\u538b\u7f29\u6587\u4ef6<\/p>\n<p>    $newZipFile = &#8216;downloads\/&#8217; . date(&#8216;YmdHis&#8217;) . &#8216;.zip&#8217;;<\/p>\n<p>    zipFolder($temporaryDir, $newZipFile);<\/p>\n<p>    \/\/ \u8f93\u51fa\u65b0\u7684\u6253\u5305\u5c01\u88c5\u540e\u7684\u6587\u4ef6\u4e0b\u8f7d\u94fe\u63a5<\/p>\n<p>    echo &#8220;\u6253\u5305\u5c01\u88c5\u6210\u529f\uff0c<a href='$newZipFile'>\u4e0b\u8f7d\u6587\u4ef6<\/a>&#8220;;<\/p>\n<p>    \/\/ \u5220\u9664\u4e34\u65f6\u6587\u4ef6\u5939<\/p>\n<p>    deleteFolder($temporaryDir);<\/p>\n<p>}<\/p>\n<p>function unzipFile($src, $dest) {<\/p>\n<p>    $zip = new ZipArchive;<\/p>\n<p>    if ($zip-&gt;open($src) === true) {<\/p>\n<p>        $zip-&gt;extractTo($dest);<\/p>\n<p>        $zip-&gt;close();<\/p>\n<p>        return true;<\/p>\n<p>    } else {<\/p>\n<p>        return false;<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p>function zipFolder($source, $destination) {<\/p>\n<p>    $zip = new ZipArchive();<\/p>\n<p>    if (!$zip-&gt;open($destination, ZipArchive::CREATE)) {<\/p>\n<p>        return false;<\/p>\n<p>    }<\/p>\n<p>    $source = rtrim($source, &#8216;\/&#8217;);<\/p>\n<p>    if (is_dir($source)) {<\/p>\n<p>        $files = new RecursiveIteratorIterator(<\/p>\n<p>            new RecursiveDirectoryIterator($source),<\/p>\n<p>            RecursiveIteratorIterator::SELF_FIRST<\/p>\n<p>        );<\/p>\n<p>        foreach ($files as $file) {<\/p>\n<p>            $file = realpath($file);<\/p>\n<p>            if (is_dir($file)) {<\/p>\n<p>                $zip-&gt;addEmptyDir(str_replace($source . &#8216;\/&#8217;, &#8221;, $file . &#8216;\/&#8217;));<\/p>\n<p>            } else if (is_file($file)) {<\/p>\n<p>                $zip-&gt;addFromString(str_replace($source . &#8216;\/&#8217;, &#8221;, $file), file_get_contents($file));<\/p>\n<p>            }<\/p>\n<p>        }<\/p>\n<p>    } else if (is_file($source)) {<\/p>\n<p>        $zip-&gt;addFromString(basename($source), file_get_contents($source));<\/p>\n<p>    }<\/p>\n<p>    return $zip-&gt;close();<\/p>\n<p>}<\/p>\n<p>function deleteFolder($dirPath) {<\/p>\n<p>    if (!is_dir($dirPath)) {<\/p>\n<p>        throw new InvalidArgumentException(&#8220;$dirPath must be a directory&#8221;);<\/p>\n<p>    }<\/p>\n<p>    if (substr($dirPath, strlen($dirPath) &#8211; 1, 1) != &#8216;\/&#8217;) {<\/p>\n<p>        $dirPath .= &#8216;\/&#8217;;<\/p>\n<p>    }<\/p>\n<p>    $files = glob($dirPath . &#8216;*&#8217;, GLOB_MARK);<\/p>\n<p>    foreach ($files as $file) {<\/p>\n<p>        if (is_dir($file)) {<a href=\"http:\/\/www.yimenyun.cn\/app-shengcheng-gongju-353.html\">\u600e\u4e48\u5c06\u7f51\u7ad9\u751f\u6210app<\/a><\/p>\n<p>            deleteFolder($file);<\/p>\n<p>        } else {<\/p>\n<p>            unlink($file);<\/p>\n<p>        }<\/p>\n<p>    }<\/p>\n<p>    rmdir($dirPath);<\/p>\n<p>}<\/p>\n<p>?&gt;<\/p>\n<p>&#8220;`<\/p>\n<p>   \u73b0\u5728\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u63d0\u4ea4 HTML \u8868\u5355\u4e0a\u4f20\u6e90\u4ee3\u7801 zip \u6587\u4ef6\uff0c\u5e76\u4f7f\u7528\u4e0a\u8ff0 PHP \u811a\u672c\u5bf9\u5176\u8fdb\u884c\u5728\u7ebf\u6253\u5305\u548c\u5c01\u88c5\u3002\u6839\u636e\u9700\u8981\uff0c\u60a8\u53ef\u4ee5\u5bf9\u8fd9\u4e2a\u8fc7\u7a0b\u8fdb\u884c\u81ea\u5b9a\u4e49\uff0c\u63d0\u4f9b\u4e0d\u540c\u7684\u7a0b\u5e8f\u5c01\u88c5\u9009\u9879\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u8fd9\u7bc7\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u8ba8\u8bba\u5982\u4f55\u4f7f\u7528 PHP \u8fdb\u884c\u5728\u7ebf\u6253\u5305\u548c\u5c01\u88c5\u5e94\u7528\u7a0b\u5e8f\uff08app\uff09\u3002\u5728\u7ebf\u6253\u5305\u6307\u7684\u662f\u5c06\u6e90\u4ee3\u7801\u5c01\u88c5\u5230\u4e00\u4e2a\u53ef\u6267\u884c\u7684\u7a0b\u5e8f\u4e2d\uff0c\u800c\u975e\u8ba9\u7528\u6237\u4ece\u6e90\u4ee3\u7801\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u3002\u8fd9\u79cd\u5728\u7ebf\u6253\u5305\u548c\u5c01\u88c5\u7684\u65b9\u6cd5\u5141\u8bb8\u5f00\u53d1\u8005\u5206\u53d1<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[3048,14,22,1184,3047],"topic":[],"class_list":["post-1488","post","type-post","status-publish","format-standard","hentry","category-hangye","tag-app","tag-14","tag-22","tag-1184"],"_links":{"self":[{"href":"https:\/\/www.yimenapp.cn\/yun\/wp-json\/wp\/v2\/posts\/1488","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenapp.cn\/yun\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenapp.cn\/yun\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenapp.cn\/yun\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenapp.cn\/yun\/wp-json\/wp\/v2\/comments?post=1488"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenapp.cn\/yun\/wp-json\/wp\/v2\/posts\/1488\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenapp.cn\/yun\/wp-json\/wp\/v2\/media?parent=1488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenapp.cn\/yun\/wp-json\/wp\/v2\/categories?post=1488"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenapp.cn\/yun\/wp-json\/wp\/v2\/tags?post=1488"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenapp.cn\/yun\/wp-json\/wp\/v2\/topic?post=1488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}