{"id":2099,"date":"2013-06-04T08:13:18","date_gmt":"2013-06-04T00:13:18","guid":{"rendered":"https:\/\/sdeno.com\/?p=2099"},"modified":"2013-06-04T08:18:06","modified_gmt":"2013-06-04T00:18:06","slug":"wordpress%e6%96%87%e4%bb%b6%e4%b8%8a%e4%bc%a0%e9%98%b2%e6%ad%a2%e5%90%8c%e5%91%bd%e5%90%8d%e6%96%87%e4%bb%b6%e8%a6%86%e7%9b%96","status":"publish","type":"post","link":"https:\/\/sdeno.com\/?p=2099","title":{"rendered":"wordpress\u6587\u4ef6\u4e0a\u4f20\u9632\u6b62\u540c\u547d\u540d\u6587\u4ef6\u8986\u76d6"},"content":{"rendered":"<p>\u5728\u4f7f\u7528<a href=\"https:\/\/sdeno.com\/\">wordpress\u5efa\u7ad9<\/a>\u7684\u65f6\u5019\u6211\u4eec\u4f1a\u53d1\u73b0\u5728\u4e0a\u4f20\u540c\u547d\u540d\u6587\u4ef6\u7684\u65f6\u5019\u4e24\u4e2a\u540d\u5b57\u4e00\u6837\u7684\u6587\u4ef6\u4e0a\u4f20\u65f6\u540e\u8005\u4f1a\u8986\u76d6\u4e4b\u524d\u7684\u6587\u4ef6\uff0c<br \/>\n\u8fd9\u6837\u4f1a\u5bfc\u81f4\u56fe\u6587\u4e0d\u4e00\u81f4\uff0c\u8fd9\u6837\u5bf9\u4e8e\u4f7f\u7528\u8001\u7248\u672c\u7684wordpress\u7ad9\u957f\u6765\u8bf4\u662f\u4e00\u4e2a\u9ebb\u70e6\uff0c\u4f46\u662f\u5347\u7ea7\u5c31\u4f1a\u628a\u539f\u6765\u4f18\u5316\u4fee\u6539\u8fc7\u7684\u4ee3\u7801\u8986\u76d6\u6389\uff0c<br \/>\n\u5176\u5b9e\u4f7f\u7528\u4e24\u79cd\u65b9\u6cd5\u53ef\u4ee5\u89e3\u51b3\u5982\u4e0b\uff1a<br \/>\n<strong>\u7b2c\u4e00\u79cd\u65b9\u6cd5\uff1a<\/strong><br \/>\n\u627e\u5230wordpress\u7a0b\u5e8f\u7684\u6839\u76ee\u5f55\u4e0b\u7684\/wp-admin\/includes\/file.php\u6587\u4ef6\uff0c\u7f16\u8f91\uff0c\u627e\u5230\u4ee5\u4e0b\u4ee3\u7801\uff0c\u5982\u4e0b\u56fe\u6240\u793a (\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u641c\u7d22\u529f\u80fd\uff0c\u641c\u7d22Move the file to the uploads dir)<\/p>\n<p>[code]\/\/ Move the file to the uploads dir<br \/>\n$new_file = $uploads[&#8216;path&#8217;] . &#8220;\/$filename&#8221;;<br \/>\nif ( false === @ move_uploaded_file( $file[&#8216;tmp_name&#8217;], $new_file ) )<br \/>\nreturn $upload_error_handler( $file,<br \/>\nsprintf( __(&#8216;The uploaded file could not be moved to %s.&#8217; ), $uploads[&#8216;path&#8217;] ) );[\/code]<br \/>\n2\u3001\u5c06\u4e0a\u8ff0\u4ee3\u7801\u66ff\u6362\u4e3a\uff1a\uff08\u5f53\u7136\u4f60\u4e5f\u53ef\u4ee5\u88c5\u4e0a\u8ff0\u4ee3\u7801\u6ce8\u91ca\uff0c\u65b9\u4fbf\u4ee5\u540e\u8fd8\u539f\uff09<\/p>\n<p>[code]\/\/ Move the file to the uploads dir<br \/>\n$new_file = $uploads[&#8216;path&#8217;] . &#8220;\/&#8221;.date(&#8220;YmdHis&#8221;).floor(microtime()*1000).&#8221;.&#8221;.$ext;<br \/>\nif ( false === @ move_uploaded_file( $file[&#8216;tmp_name&#8217;], $new_file ) )<br \/>\nreturn $upload_error_handler<br \/>\n( $file, sprintf( __(&#8216;The uploaded file could not be moved to %s.&#8217; ), $uploads[&#8216;path&#8217;] ) );[\/code]<br \/>\n\u4fdd\u5b58file.php,\u8fd9\u6837\u5c31\u53ef\u4ee5\u5b9e\u73b0wordpress\u4e0a\u4f20\u56fe\u7247\u81ea\u52a8\u91cd\u547d\u540d\u4e86\u3002<\/p>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u610f\u601d\u5c31\u662f\uff0c\u4fdd\u5b58\u540e\u8986\u76d6\u539f\u6587\u4ef6\uff0c\u90a3\u4e48\u4e0a\u4f20\u6587\u4ef6\u5c31\u4f1a\u4ee5\u201c\u5e74\u6708\u65e5\u65f6\u5206\u79d2+\u5343\u4f4d\u6beb\u79d2\u6574\u6570\u201d\u7684\u683c\u5f0f\u91cd\u547d\u540d\u6587\u4ef6\u3002\u8fd9\u5c31\u518d\u4e5f\u4e0d\u7528\u62c5\u5fc3\u56fe\u7247\u6587\u4ef6\u540d\u76f8\u540c\u800c\u8986\u76d6\u4e86\u539f\u6587\u4ef6\u3002<br \/>\n<strong>\u7b2c2\u79cd\u65b9\u6cd5\uff1a<\/strong><br \/>\n\u5728\u6211\u4eecwordpress\u7f51\u7ad9\u6a21\u677f\u76ee\u5f55\uff08wp-content\\themes\\\u6a21\u5757\u6587\u4ef6\u540d\\\uff09\u4e0b\u7684functions.php\u4e2d\u52a0\u5165\u4ee5\u4e0b\u4ee3\u7801 \uff0c\u76f4\u63a5\u653e\u5728functions.php\u6587\u4ef6\u7684\u6700\u540e\uff08\u6ce8\u610f\u662f ?&gt; \u4e4b\u524d\uff0c\u5982\u4e0b\u56fe\uff09\u5c31\u53ef\u4ee5\u3002<\/p>\n<p>[code]function new_filename($filename) {<br \/>\n$info = pathinfo($filename);<br \/>\n$ext = empty($info[&#8216;extension&#8217;]) ? \u201d : \u2018.\u2019 . $info[&#8216;extension&#8217;];<br \/>\n$name = basename($filename, $ext);<br \/>\nreturn substr(md5($name), 0, 20) . $ext;<br \/>\n}<br \/>\nadd_filter(\u2018sanitize_file_name\u2019, \u2018new_filename\u2019, 10);[\/code]<br \/>\n\u4fdd\u5b58functions.php\uff0c\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u5c06\u6587\u4ef6\u540d\u79f0\u5728\u4e0a\u4f20\u8fc7\u7a0b\u4e2d\u5c31\u81ea\u52a8\u91cd\u547d\u540d\u4e86\u3002\u540d\u5b57\u89c4\u5219\u4e3a\u7cfb\u7edf\u81ea\u52a8\u751f\u6210\u7684\u4e00\u4e2a32\u4f4d\u7684MD5\u52a0\u5bc6\u6587\u4ef6\u540d\u3002\uff08\u56e0\u4e3a32\u4f4d\u6587\u4ef6\u540d\u6709\u70b9\u957f\uff0c\u6240\u4ee5\u6211\u4eec\u5728substr(md5($name), 0, 20) \u4e2d\u622a\u65ad\u4e86\u5c06\u5176\u8bbe\u7f6e\u4e3a20\u4f4d\uff09.<\/p>\n<p>PS:\u4e24\u79cd\u65b9\u6cd5\u5404\u6709\u6240\u957f\uff0c\u7b2c\u4e00\u79cd\u65b9\u6cd5\u4e0d\u4f1a\u56e0\u4e3a\u66f4\u6362\u6a21\u677f\u800c\u5bfc\u81f4\u5931\u6548\uff0c\u7b2c\u4e8c\u79cd\u65b9\u6cd5\u5982\u679c\u66f4\u6362\u6a21\u677f\u5c31\u9700\u8981\u91cd\u65b0\u52a0\u5165\u4ee3\u7801\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4f7f\u7528wordpress\u5efa\u7ad9\u7684\u65f6\u5019\u6211\u4eec\u4f1a\u53d1\u73b0\u5728\u4e0a\u4f20\u540c\u547d\u540d\u6587\u4ef6\u7684\u65f6\u5019\u4e24\u4e2a\u540d\u5b57\u4e00\u6837\u7684\u6587\u4ef6\u4e0a\u4f20\u65f6\u540e\u8005\u4f1a\u8986\u76d6\u4e4b\u524d\u7684\u6587\u4ef6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,11],"tags":[],"class_list":["post-2099","post","type-post","status-publish","format-standard","hentry","category-wordpress","category-11"],"_links":{"self":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/2099","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2099"}],"version-history":[{"count":0,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/2099\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}