{"id":73,"date":"2012-11-28T19:01:34","date_gmt":"2012-11-28T11:01:34","guid":{"rendered":"http:\/\/www.yeetrack.com\/post\/2012-11-28\/php%25E6%2593%258D%25E4%25BD%259C%25E7%259B%25AE%25E5%25BD%2595%25E6%2596%2587%25E4%25BB%25B6"},"modified":"2013-04-20T17:24:33","modified_gmt":"2013-04-20T09:24:33","slug":"php%e6%93%8d%e4%bd%9c%e7%9b%ae%e5%bd%95%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/www.yeetrack.com\/?p=73","title":{"rendered":"php\u64cd\u4f5c\u76ee\u5f55\u6587\u4ef6"},"content":{"rendered":"<p>php\u63d0\u4f9b\u5bf9\u670d\u52a1\u5668\u4e2d\u7684\u76ee\u5f55\u8fdb\u884c\u64cd\u4f5c\u7684\u51fd\u6570\uff0c\u64cd\u4f5c\u5305\u62ec\u521b\u5efa\u3001\u8bfb\u53d6\u3001\u590d\u5236\u3001\u5220\u9664\u3002<\/p>\n<p><!--more--><\/p>\n<p>php\u51fd\u6570\u5bf9\u4e8e\u76ee\u5f55\u7684\u89e3\u6790\u652f\u6301\u7edd\u5bf9\u8def\u5f84\u548c\u76f8\u5bf9\u8def\u5f84\u3002\u8fd9\u5199\u51fd\u6570\u6709basename()\u3001dirname()\u3001pathinfo()\u3001opendir()\u3001readdir()\u3001closedir()\u3001rewinddir()\u7b49\u3002\u5177\u4f53\u89c1\u4e0b\u9762\u4ee3\u7801\uff1a<\/p>\n<pre config=\"brush:php;toolbar:false;\">&lt;?php\n    \/**\n     * @author youthflies\n     * \u6587\u4ef6\u76ee\u5f55\u64cd\u4f5c\n     *\/\n    header(&quot;Content-Type:text\/html;charset=utf-8&quot;);\n         \n    $filePath = &quot;\/home\/youthflies\/downloads\/jdk-6u37-linux-i586.bin&quot;;\n    if(file_exists($filePath))\n        echo &quot;\u7edd\u5bf9\u8def\u5f84\u6b63\u786e!&quot; .&quot;&lt;br \/&gt;&quot;;\n         \n    if(file_exists(&quot;..\/..\/..\/..\/downloads\/jdk-6u37-linux-i586.bin&quot;))\n        echo &quot;\u76f8\u5bf9\u8def\u5f84\u6b63\u786e!&quot; . &quot;&lt;br \/&gt;&quot;;\n             \n    \/\/basename()\u51fd\u6570\u8fd4\u56de\u8def\u5f84\u4e2d\u7684\u6587\u4ef6\u540d\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3a\u53ef\u9009\uff0c\u5982\u679c\u624b\u52a8\u8f93\u5165\u4e86\u62d3\u5c55\u540d\uff0c\u8be5\u51fd\u6570\u5c31\u8fd4\u56de\u6587\u4ef6\u540d\uff08\u4e0d\u5e26\u62d3\u5c55\u540d\uff09    \n    echo basename($filePath) . &quot;&lt;br \/&gt;&quot;;\n    echo basename($filePath, &quot;.bin&quot;) . &quot;&lt;br \/&gt;&quot;;\n         \n    \/\/dirname()\u4e0ebasename()\u76f8\u53cd\uff0c\u5b83\u8fd4\u56de\u7ed9\u5b9a\u6587\u4ef6\u7684\u8def\u5f84\u90e8\u5206\n    echo dirname($filePath) . &quot;&lt;br \/&gt;&quot;;\n         \n    \/\/pathinfo()\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u5173\u8054\u6570\u7ec4\uff0c\u5305\u62ec\u8def\u5f84\u540d\u3001\u6587\u4ef6\u540d\u3001\u57fa\u672c\u540d\u548c\u62d3\u5c55\u540d\uff0c\u952e\u540d\u5206\u522b\u662fdirname\u3001basename\u3001filename\u548cextension\n    print_r(pathinfo($filePath));\n    echo &quot;&lt;br \/&gt;&quot;;\n         \n    \/**\n     * \u5982\u679c\u8981\u904d\u5386\u67d0\u4e2a\u8def\u5f84\uff0c\u53ef\u4ee5\u7528opendir()\u3001readdir()\u3001closedir()\u548crewinddir()\u51fd\u6570\n     * opendir()\u51fd\u6570\uff0c\u63a5\u53d7\u4e00\u4e2a\u76ee\u5f55\u4f5c\u4e3a\u53c2\u6570\uff0c\u8fd4\u56de\u4e00\u4e2a\u76ee\u5f55\u53e5\u67c4\uff0c\u5982\u679c\u5931\u8d25\u5219\u8fd4\u56defalse\n     * readdir()\u51fd\u6570\uff0c\u63a5\u53d7opendir()\u51fd\u6570\u8fd4\u56de\u7684\u53e5\u67c4\u4f5c\u4e3a\u53c2\u6570\uff0c\u51fd\u6570\u8fd4\u56de\u8be5\u76ee\u5f55\u53e5\u67c4\u7684\u4e00\u4e2a\u6587\u4ef6\uff0c\u4e14\u6307\u9488\u5411\u540e\u79fb\u52a8\uff0c\u901a\u5e38\u901a\u8fc7\u5faa\u73af\u6765\u904d\u5386\u76ee\u5f55\u7684\u5168\u90e8\u5185\u5bb9\n     * closedir()\u63a5\u53d7opendir()\u51fd\u6570\u8fd4\u56de\u7684\u53e5\u67c4\u4f5c\u4e3a\u53c2\u6570\uff0c\u6765\u5173\u95ed\u6253\u5f00\u7684\u76ee\u5f55\n     * rewinddir()\u63a5\u53d7opendir()\u51fd\u6570\u8fd4\u56de\u7684\u53e5\u67c4\u4f5c\u4e3a\u53c2\u6570\uff0c\u5c06\u76ee\u5f55\u6307\u9488\u91cd\u7f6e\u5230\u5f00\u59cb\u5904\uff0c\u5373\u76ee\u5f55\u7684\u5f00\u5934\n     *\/\n    $dirName = &quot;\/home\/youthflies\/downloads&quot;;\n    $dirHandle = opendir($dirName);\n    echo '&lt;table border=&quot;0&quot; align=&quot;center&quot; width=&quot;600&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;';\n    echo '&lt;tr align =&quot;left&quot; bgcolor=&quot;blue&quot;&gt;';\n    echo '&lt;th&gt;\u6587\u4ef6\u540d&lt;\/th&gt;&lt;th&gt;\u6587\u4ef6\u5927\u5c0f&lt;\/th&gt;&lt;th&gt;\u6587\u4ef6\u7c7b\u578b&lt;\/th&gt;&lt;th&gt;\u4fee\u6539\u65f6\u95f4&lt;\/th&gt;&lt;\/tr&gt;';\n    $num = 0;\n    while($fileName = readdir($dirHandle))\n    {\n        $file = $dirName . '\/' . $fileName;\n        $bgcolor = $num++%2==0 ? &quot;blue&quot; : &quot;&quot;;\n        echo '&lt;tr bgcolor=' . $bgcolor . '&gt;';\n        echo '&lt;td&gt;' . $file . '&lt;\/td&gt;';\n        echo '&lt;td&gt;' . filetype($file) . '&lt;\/td&gt;';\n        echo '&lt;td&gt;' . filesize($file) . '&lt;\/td&gt;';\n        echo '&lt;td&gt;' . date(&quot;Y-m-d h:i:s&quot;, filemtime($file)) . '&lt;\/td&gt;';\n        echo '&lt;\/tr&gt;&lt;tr&gt;';\n    }\n    echo '&lt;\/table&gt;';\n    closedir($dirHandle);\n         \n    \/**\n     * \u4e0b\u9762\u662f\u4e2a\u8ba1\u7b97\u76ee\u5f55\u5927\u5c0f\u7684\u4f8b\u5b50\uff08\u4f7f\u7528\u7684\u9012\u5f52\uff09\n     *\/\n    function dirSize($dirName)\n    {\n        $dir_Size = 0;\n        if(is_file($dirName))\n            return filesize($dirName);\n        $dirHandle = opendir($dirName);\n        if($dirHandle == false)\n            return;\n        while($fileName = readdir($dirHandle))\n        {\n            if($fileName!='.' &amp;&amp; $fileName!='..')\n            {\n                $file = $dirName . '\/' . $fileName;\n                if(is_file($file))\n                    $dir_Size += filesize($file);\n                elseif (is_dir($file))\n                    $dir_Size += dirSize($file);\n            }\n        }\n        closedir($dirHandle);\n        return $dir_Size;\n    }\n    \/\/\u8c03\u7528dirSize()\u51fd\u6570\u8ba1\u7b97downloads\u76ee\u5f55\u7684\u5927\u5c0f\n    echo dirSize(&quot;\/home\/youthflies\/downloads&quot;)\/(1024*1024) . &quot;MB&quot; . &quot;&lt;br \/&gt;&quot;;\n         \n    \/\/disk_total_space()\u548cdisk_free_space()\u51fd\u6570\u5206\u522b\u7528\u6765\u8ba1\u7b97\u5f53\u524d\u78c1\u76d8\u7684\u603b\u5927\u5c0f\u548c\u5269\u4f59\u5927\u5c0f\n    echo disk_total_space(&quot;\/home&quot;)\/(1024*1024) . &quot;MB&quot; . &quot;&lt;br \/&gt;&quot;;\n    echo disk_free_space(&quot;\/home&quot;)\/(1024*1024) . &quot;MB&quot; . &quot;&lt;br \/&gt;&quot;;\n         \n    \/\/mkdir()\u51fd\u6570\u7528\u4e8e\u521b\u5efa\u76ee\u5f55\uff1brmdir()\u51fd\u6570\u7528\u4e8e\u5220\u9664\u7a7a\u7684\u76ee\u5f55\uff0c\u5982\u679c\u8981\u5220\u9664\u975e\u7a7a\u76ee\u5f55\uff0c\u5c31\u8981\u5148\u9012\u5f52\u5220\u9664\u8be5\u76ee\u5f55\u7684\u5176\u4ed6\u6587\u4ef6\uff1b\u5220\u9664\u6587\u4ef6\u4f7f\u7528unlink()\u51fd\u6570\n    $dirName2 = &quot;\/home\/youthflies\/downloads\/mktem&quot;;\n    if(file_exists($dirName2))\n    {\n        echo &quot;\u76ee\u5f55\u5df2\u7ecf\u5b58\u5728&quot; . &quot;&lt;br \/&gt;&quot;;\n        if(rmdir(&quot;\/home\/youthflies\/downloads\/mktem&quot;))\n            echo &quot;\u5220\u9664\/home\/youthflies\/downloads\/mktem \u6210\u529f&quot; . &quot;&lt;br \/&gt;&quot;;\n    }\n    else\n    {\n        if(mkdir($dirName2))\n        {\n            echo &quot;\u521b\u5efa \/home\/youthflies\/downloads\/mktem \u6210\u529f&quot;;\n            \/\/\u5220\u9664mktem\u76ee\u5f55\u4e0b\u7684tem.txt\u6587\u4ef6\n            exec(&quot;touch tem.txt&quot;); \/\/\u6700\u597d\u4e0d\u8981\u76f4\u63a5\u8c03\u7528\u64cd\u4f5c\u7cfb\u7edf\u7684shell\u547d\u4ee4\n            if(file_exists(&quot;mktem\/tem.txt&quot;))\n                unlink(&quot;tem.txt&quot;, &quot;mktem&quot;);\n        }\n    }\n    \/\/\u5982\u679c\u60f3\u8981\u590d\u5236\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528copy()\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u53ea\u80fd\u590d\u5236\u666e\u901a\u6587\u4ef6\uff0c\u5982\u679c\u60f3\u590d\u5236\u6574\u4e2a\u6587\u4ef6\u5939\uff0c\u8981\u4f7f\u7528\u9012\u5f52\u3002\n    copy(&quot;\/home\/youthflies\/downloads\/source.txt&quot;, &quot;\/home\/youthflies\/downloads\/destination.txt&quot;);\n?&gt;<\/pre>\n<p>\u4e0a\u9762\u4ee3\u7801\u8f93\u5165\u7ed3\u679c\uff1a<\/p>\n<p>\u7edd\u5bf9\u8def\u5f84\u6b63\u786e!<br \/>\u76f8\u5bf9\u8def\u5f84\u6b63\u786e!<br \/>jdk-6u37-linux-i586.bin<br \/>jdk-6u37-linux-i586<br \/>\/home\/youthflies\/downloads<br \/>Array( &nbsp;&nbsp;&nbsp;[dirname] =&gt; \/home\/youthflies\/downloads &nbsp;&nbsp;&nbsp;[basename] =&gt; jdk-6u37-linux-i586.bin &nbsp;&nbsp;&nbsp;[extension] =&gt; bin &nbsp;&nbsp;&nbsp;[filename] =&gt; jdk-6u37-linux-i586)<\/p>\n<p>\u6587\u4ef6\u540d\u6587\u4ef6\u5927\u5c0f\u6587\u4ef6\u7c7b\u578b\u4fee\u6539\u65f6\u95f4\/home\/youthflies\/downloads\/\u767e\u5ea6Java Web\u5b89\u5168\u7f16\u7801\u89c4\u8303\uff082012\u4fee\u6539\uff09.pdffile4607442012-11-20 01:15:03<br \/>\/home\/youthflies\/downloads\/source.txtfile02012-11-28 02:21:54<br \/>\/home\/youthflies\/downloads\/mktemdir40962012-11-28 03:30:00<br \/>\/home\/youthflies\/downloads\/node-v0.8.14dir40962012-11-25 10:14:26<br \/>\/home\/youthflies\/downloads\/eclipsedir40962012-09-20 04:40:18<br \/>\/home\/youthflies\/downloads\/linkapache-tomcat-7.0.33.tar.gzlink76960042012-11-28 10:01:40<br \/>\/home\/youthflies\/downloads\/eclipse-jee-juno-SR1-linux-gtk.tarfile2672435202012-11-19 11:43:15<br \/>\/home\/youthflies\/downloads\/jdk-6u37-linux-i586.binfile717640732012-11-27 02:13:01<br \/>\/home\/youthflies\/downloads\/selenium-server.jarfile161750992012-11-22 06:53:56<br \/>\/home\/youthflies\/downloads\/.dir40962012-11-28 03:30:00<br \/>\/home\/youthflies\/downloads\/google-chrome-stable_current_i386.debfile343789882012-11-19 11:12:23<br \/>\/home\/youthflies\/downloads\/\u65e0\u6807\u9898\u6587\u6863~file02012-11-27 07:23:07<br \/>\/home\/youthflies\/downloads\/burpsuite_v1.4.01dir40962038-01-19 11:14:07<br \/>\/home\/youthflies\/downloads\/bnac-ubuntu-1.0.1.tar.gzfile77992012-11-19 08:05:28<br \/>\/home\/youthflies\/downloads\/apache-tomcat-7.0.33dir40962012-11-26 04:19:28<br \/>\/home\/youthflies\/downloads\/\u65e0\u6807\u9898\u6587\u6863file3192012-11-27 07:24:44<br \/>\/home\/youthflies\/downloads\/apache-tomcat-7.0.33.tar.gzfile76960042012-11-28 10:01:40<br \/>\/home\/youthflies\/downloads\/destination.txtfile02012-11-28 03:30:00<br \/>\/home\/youthflies\/downloads\/soapUI-x32-4.5.1.shfile1347171902012-11-26 02:37:44<br \/>\/home\/youthflies\/downloads\/..dir40962012-11-28 06:52:40<br \/>\/home\/youthflies\/downloads\/davmail_4.1.0-2042-1_all.debfile50549422012-11-23 01:55:49<br \/>\/home\/youthflies\/downloads\/ideaIU-11.1.4.tar.zipfile1939174812012-11-22 04:56:52<br \/>\/home\/youthflies\/downloads\/\u767e\u5ea6web\u5b89\u5168\u6d4b\u8bd5_2012_inf\u5f00\u653e\u65e5.pptxfile4593132012-11-28 12:07:33<br \/>\/home\/youthflies\/downloads\/xampp-linux-1.8.1.tar.gzfile847330452012-11-20 12:26:43<br \/>1150.3873596191MB<br \/>63830.78515625MB<br \/>41001.578125MB<br \/>\u76ee\u5f55\u5df2\u7ecf\u5b58\u5728<br \/>\u5220\u9664\/home\/youthflies\/downloads\/mktem \u6210\u529f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>php\u63d0\u4f9b\u5bf9\u670d\u52a1\u5668\u4e2d\u7684\u76ee\u5f55\u8fdb\u884c\u64cd\u4f5c\u7684\u51fd\u6570\uff0c\u64cd\u4f5c\u5305\u62ec\u521b\u5efa\u3001\u8bfb\u53d6\u3001\u590d\u5236\u3001\u5220\u9664\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[33],"tags":[24,7],"class_list":["post-73","post","type-post","status-publish","format-standard","hentry","category-coding","tag-php","tag-7"],"views":2389,"_links":{"self":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/73","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=73"}],"version-history":[{"count":2,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/73\/revisions"}],"predecessor-version":[{"id":383,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/73\/revisions\/383"}],"wp:attachment":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}