{"id":462,"date":"2014-07-07T06:31:59","date_gmt":"2014-07-07T06:31:59","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=462"},"modified":"2014-07-07T06:31:59","modified_gmt":"2014-07-07T06:31:59","slug":"php%e5%88%a0%e9%99%a4%e6%8c%87%e5%ae%9a%e6%96%87%e4%bb%b6%e4%b8%ad%e7%9a%84%e6%8c%87%e5%ae%9a%e5%86%85%e5%ae%b9","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/462.html","title":{"rendered":"PHP\u5220\u9664\u6307\u5b9a\u6587\u4ef6\u4e2d\u7684\u6307\u5b9a\u5185\u5bb9[bak]"},"content":{"rendered":"<p><span style=\"color: #333333;\">\u8fd9\u4e2aPHP\u811a\u672c\u7684\u76ee\u7684\u662f\u904d\u5386\u76ee\u5f55\uff0c\u627e\u5230\u6240\u6709\u6307\u5b9a\u6587\u4ef6\u540d\u7684\u6587\u4ef6\uff0c\u5e76\u5220\u9664\u5176\u4e2d\u6307\u5b9a\u7684\u5b57\u7b26\u4e32\u3002<\/span><\/p>\n<pre class=\"lang:php decode:true \">&lt;?php\n\/\/\u529f\u80fd\uff1a\u5220\u9664\u6307\u5b9a\u76ee\u5f55(\u5305\u62ec\u5b50\u76ee\u5f55)\u4e0b\u6240\u6709\u6307\u5b9a\u6587\u4ef6\u4e2d\u6307\u5b9a\u5b57\u7b26\u4e32\n$tmpfiledir = $_SERVER[\"DOCUMENT_ROOT\"].'tmp.txt';\nfunction del($getstr)\n{\n\t$isbak = true; \/\/\u662f\u5426\u5907\u4efd\u539f\u6587\u4ef6\uff0ctrue\u4e3a\u5907\u4efd\uff0cfalse\u4e0d\u5907\u4efd\n\tglobal $tmpfiledir;\n\t$fr = fopen($tmpfiledir,\"r\") or die('\u672a\u80fd\u6253\u5f00\u4e34\u65f6\u6587\u4ef6');\n\twhile($row = fgets($fr))\n\t{\n\t\tif(empty($row)) break;\n\t\t$row = trim($row);\n\t\t$opp = fopen($row,\"r\") or die(\"\u672a\u80fd\u6253\u5f00$row\");\n\t\t$str = fread($opp,filesize($row)) or die(\"\u4e0d\u80fd\u8bfb$row\");\n\t\t$str = str_replace($getstr,\"\",$str);\n\t\tfclose($opp);\n\t\tif($isbak){\n\t\t\tcopy($row,$row.'.bak') or die(\"\u5907\u4efd\u6587\u4ef6\u5931\u8d25\");\n\t\t}\n\t\t$ref = fopen($row,\"w\") or die(\"\u91cd\u65b0\u6253\u5f00\u6587\u4ef6\u5931\u8d25\");\n\t\tfwrite($ref,$str) or die(\"\u91cd\u65b0\u5199\u5165\u6587\u4ef6\u5931\u8d25\");\n\t}\n}\n\nfunction traverse($path) {\n\tglobal $name,$tmpfiledir;\n\t$current_dir = opendir($path);    \/\/opendir()\u8fd4\u56de\u4e00\u4e2a\u76ee\u5f55\u53e5\u67c4,\u5931\u8d25\u8fd4\u56defalse\n\tif($current_dir == false)\n\treturn false;\n\twhile(($file = readdir($current_dir)) !== false) {    \/\/readdir()\u8fd4\u56de\u6253\u5f00\u76ee\u5f55\u53e5\u67c4\u4e2d\u7684\u4e00\u4e2a\u6761\u76ee\n\t\t$sub_dir = $path . DIRECTORY_SEPARATOR . $file;    \/\/\u6784\u5efa\u5b50\u76ee\u5f55\u8def\u5f84\n\t\tif($file == '.' || $file == '..') {\n\t\t\tcontinue;\n\t\t} else if(is_dir($sub_dir)) {    \/\/\u5982\u679c\u662f\u76ee\u5f55,\u8fdb\u884c\u9012\u5f52\n\t\t\ttraverse($sub_dir);\n\t\t} else {    \/\/\u5982\u679c\u662f\u6587\u4ef6,\u518d\u505a\u6bd4\u8f83\n\t\t\t$fileinfo = pathinfo($sub_dir);\n\t\t\tif($fileinfo['basename'] == $name)\n\t\t\t{\n\t\t\t\t$fopen = fopen($tmpfiledir,\"a\");\n\t\t\t\tfwrite($fopen,$sub_dir.\"rn\");\n\t\t\t\tfclose($fopen);\n\t\t\t}\n\t\t}\n\t}\n\treturn true;\n}\n\nif(isset($_POST[\"name\"]) &amp;&amp; isset($_POST[\"dir\"]) &amp;&amp; isset($_POST[\"str\"])) {\n\t$name = $_POST[\"name\"];\n\ttraverse($_POST[\"dir\"]) or die(\"\u672a\u80fd\u521b\u5efa\u4e34\u65f6\u6587\u4ef6\uff0c\u8bf7\u68c0\u67e5\u7f51\u7ad9\u6839\u76ee\u5f55\u662f\u5426\u53ef\u5199\");\n\tdel($_POST[\"str\"]);\n\techo \"\u6210\u529f\";\n\tunlink($tmpfiledir);\n} else {\n\techo \"&lt;p&gt;\u8f93\u5165\u76f8\u5173\u4fe1\u606f&lt;\/p&gt;\";\n}\n?&gt;\n&lt;form name=\"input\" action=\"\" method=\"post\"&gt;\n\u8f93\u5165\u76ee\u6807\u6587\u4ef6\u5939:&lt;input type=\"text\" name=\"dir\"\/&gt;\n\u8f93\u5165\u76ee\u6807\u6587\u4ef6\u540d:&lt;input type=\"text\" name=\"name\"\/&gt;\n\u8f93\u5165\u9700\u8981\u5220\u9664\u7684\u5b57\u7b26\u4e32:&lt;input type=\"text\" name=\"str\" \/&gt;\n&lt;input type=\"submit\" value=\"\u63d0\u4ea4\" \/&gt;\n&lt;\/form&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p>\u8fd9\u91cc\u5199\u4e86\u4e24\u4e2a\u51fd\u6570\uff0c\u51fd\u6570traverse\u5c06\u67e5\u627e\u5230\u7684\u6307\u5b9a\u6587\u4ef6\u8def\u5f84\u5199\u5728\u4e00\u4e2a\u4e34\u65f6\u6587\u4ef6\u91cc\uff0c\u51fd\u6570del\u5220\u9664\u8fd9\u4e9b\u6587\u4ef6\u91cc\u7684\u6307\u5b9a\u5b57\u7b26\u4e32\u3002\u5176\u5b9e\u53ef\u4ee5\u76f4\u63a5\u5728\u904d\u5386\u7684\u65f6\u5019\u5c31\u5220\u9664\uff0c\u6839\u672c\u4e0d\u7528\u751f\u6210\u4ec0\u4e48\u4e34\u65f6\u6587\u4ef6\u3002\u8fd9\u4e2a\u811a\u672c\u4e0d\u652f\u6301\u901a\u914d\u7b26\uff0c\u6240\u4ee5\u6587\u4ef6\u540d\u5fc5\u987b\u8981\u6307\u5b9a\u3002\u4f5c\u7528\u561b(\u4e5f\u662f\u6211\u5199\u8fd9\u4e2a\u7684\u7406\u7531)\uff0c\u53ef\u4ee5\u6279\u91cf\u5220\u9664\u6211\u4eec\u6302\u5728\u670d\u52a1\u5668\u4e0a\u7684\u4e00\u53e5\u8bdd\u6728\u9a6c\u3002<\/p>\n<div style=\"color: gray;\"><small>\u6765\u6e90\uff1a\u00a0&lt;<a href=\"http:\/\/www.leavesongs.com\/PHP\/phpdelfile.html\" target=\"_blank\">http:\/\/www.leavesongs.com\/PHP\/phpdelfile.html<\/a><small>&gt;<\/small><\/small><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u4e2aPHP\u811a\u672c\u7684\u76ee\u7684\u662f\u904d\u5386\u76ee\u5f55\uff0c\u627e\u5230\u6240\u6709\u6307\u5b9a\u6587\u4ef6\u540d\u7684\u6587\u4ef6\uff0c\u5e76\u5220\u9664\u5176\u4e2d\u6307\u5b9a\u7684\u5b57\u7b26\u4e32\u3002 &lt;?php \/\/\u529f\u80fd [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,12],"tags":[48],"class_list":["post-462","post","type-post","status-publish","format-standard","hentry","category-programing","category-tools","tag-php"],"views":2064,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/462","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=462"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/462\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}