{"id":12262,"date":"2021-11-26T00:00:00","date_gmt":"2021-11-25T16:00:00","guid":{"rendered":"https:\/\/fgchen.com\/wpedu2\/2021\/11\/26\/%e3%80%90wordpress%e3%80%91%e4%bd%bf%e7%94%a8vscode%e7%9a%84sftp%e4%be%86%e6%8e%9b%e8%bc%89wordpress%e7%9a%84wp-content%e7%9b%ae%e9%8c%84\/"},"modified":"2026-03-30T14:34:00","modified_gmt":"2026-03-30T06:34:00","slug":"%e3%80%90wordpress%e3%80%91%e4%bd%bf%e7%94%a8vscode%e7%9a%84sftp%e4%be%86%e6%8e%9b%e8%bc%89wordpress%e7%9a%84wp-content%e7%9b%ae%e9%8c%84","status":"publish","type":"post","link":"https:\/\/fgchen.com\/wpedu\/2021\/11\/%e3%80%90wordpress%e3%80%91%e4%bd%bf%e7%94%a8vscode%e7%9a%84sftp%e4%be%86%e6%8e%9b%e8%bc%89wordpress%e7%9a%84wp-content%e7%9b%ae%e9%8c%84\/","title":{"rendered":"\u3010WordPress\u3011\u4f7f\u7528VSCode\u7684SFTP\u4f86\u639b\u8f09WordPress\u7684wp-content\u76ee\u9304"},"content":{"rendered":"\u5728\u9019\u88cf\uff0c\u6211\u505a\u4e86\u4e00\u500b\u52d5\u4f5c\uff0c\u70ba\u4e86\u65b9\u4fbf\u6e2c\u8a66\u958b\u767cWordPress\u7684\u5916\u639b\u8207\u4e3b\u984c\uff0c\u6211\u8a2d\u7f6e\u4e86sftp\u7684\u9060\u7aef\u76ee\u9304\u81f3\uff1a\n\n<div>\n<div>\u00a0 \u00a0 &#8220;remotePath&#8221;: &#8220;\/home\/u1085100\/public_html\/wp2\/wp-content&#8221;,<\/div>\n<\/div>\n\n<div><\/div>\n\n<div>\u5728\u672c\u5730\u7aef\uff0c\u6211\u5247\u5efa\u7acb\u4e09\u500b\u8cc7\u6599\u593e\uff1a<\/div>\n\n<ul>\n    <li>languages\uff0c\u8a9e\u7cfb\u6a94\u76ee\u9304<\/li>\n    <li>plugins\uff0c\u5916\u639b\u76ee\u9304<\/li>\n    <li>themes\uff0c\u4e3b\u984c\u76ee\u9304<\/li>\n<\/ul>\n\n\u6211\u7684\u60f3\u6cd5\u662f\uff0c\u7576\u6211\u8981\u5beb\u6216\u6e2c\u8a66\u4e00\u500b\u5916\u639b\u6642\uff0c\u6211\u5c31\u5728plugins\u4e0b\u5efa\u4e00\u500b\u5916\u639b\u7684\u8cc7\u6599\u593e\uff0c\u7136\u5f8c\u518d\u7528sftp:sync local-&gt;remote\u7684\u65b9\u6cd5\uff0c\u5c07\u65b0\u589e\u7684\u8cc7\u6599\u593e\u50b3\u4e0a\u4e3b\u6a5f\u3002\n\n<div><a href=\"https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2021\/11\/VSCode-WordPressDevelopmentDirectory.png\"><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-17920\" src=\"https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2021\/11\/VSCode-WordPressDevelopmentDirectory.png\" alt=\"\" width=\"1025\" height=\"428\" \/><\/a>\n<div><\/div>\n<\/div>\n\n<div><\/div>\n\n<div>\u5efa\u597d\u5f8c\uff0c\u6211\u8981\u6e2c\u8a66<span style=\"font-size: 24pt\"><a href=\"https:\/\/github.com\/flacoman91\/wordpress-demos\/tree\/master\/file-upload-example\" target=\"_blank\" rel=\"noopener\">file-upload-example<\/a><\/span>\u9019\u500b\u5916\u639b\u7bc4\u4f8b\uff0c\u90a3\u9ebc\u6211\u5c31\u5728\u672c\u5730\u7aef\u7684plugins\u5efa\u7acb<strong class=\"final-path\">file-upload-example<\/strong>\u8cc7\u6599\u593e\uff0c\u4e26\u5728\u8a72\u8cc7\u6599\u593e\u4e0b\u5efa\u7acb<strong class=\"final-path\">file-upload-example.php<\/strong>\uff0c<\/div>\n\n<div><\/div>\n\n<a href=\"https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2021\/11\/VSCode-WordPressDevelopmentDirectory-1.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-17921\" src=\"https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2021\/11\/VSCode-WordPressDevelopmentDirectory-1.png\" alt=\"\" width=\"975\" height=\"553\" \/><\/a>\n\n<div><\/div>\n\n<div><\/div>\n\n<div>\n\n<hr \/>\n\n\u7a0b\u5f0f\u78bc\uff1a\n\n<\/div>\n\n<div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">&lt;?php \n\/* \nPlugin Name: File Upload Example\nDescription: demo plugin that demonstrates how to do file upload from admin page.\nAuthor: Richard Dinh\n\/\/http:\/\/wordpress.stackexchange.com\/questions\/98375\/how-to-upload-image-with-simple-form\nthis code is a demo only. You really should do more validation and stuff\n*\/\n\n\/\/ add the admin options page\nadd_action('admin_menu', 'file_upload_example_admin_add_page');\n\nfunction file_upload_example_admin_add_page() {\n    add_options_page('File Upload Example', 'File Upload Example', 'manage_options', 'file-upload-example', 'file_upload_example_options_page');    \n\n}\n\nfunction file_upload_example_options_page() {\n    if ( empty( $_FILES ) ){\n?&gt;\n    &lt;div&gt;\n        &lt;h2&gt;Upload a file here&lt;\/h2&gt;\n        &lt;form action=\"\" method=\"post\" enctype=\"multipart\/form-data\"&gt;\n        &lt;?php wp_nonce_field('csv-import'); ?&gt;\n\n        &lt;label for=\"file\"&gt;Filename:&lt;\/label&gt;\n        &lt;input type=\"file\" name=\"file\" id=\"file\"&gt;&lt;br&gt;\n        &lt;input type=\"submit\" name=\"save\" value=\"save\"&gt;\n        &lt;\/form&gt;\n    &lt;\/div&gt;\n    &lt;?php } \n    else{ \n      if ( ! function_exists( 'wp_handle_upload' ) ) \n          require_once( ABSPATH . 'wp-admin\/includes\/file.php' );\n          $uploadedfile = $_FILES['file'];\n          $upload_overrides = array( 'test_form' =&gt; false );\n          $movefile = wp_handle_upload( $uploadedfile, $upload_overrides );\n          if ( $movefile ) {\n              echo \"File is valid, and was successfully uploaded.n\";\n              var_dump( $movefile );\n              \/\/ here you can do some stuff with this\n          } else {\n              echo \"Possible file upload attack!n\";\n          }\n    }\n}<\/pre>\n<\/div>\n\n&nbsp;\n\n\u5b58\u6a94(\u6216\u6309\u4e0bctrls+S)\u5c31\u53ef\u4ee5\u5728\u9060\u7aef\u81ea\u52d5\u5efa\u7acb<strong class=\"final-path\">file-upload-example<\/strong>\u8cc7\u6599\u593e\uff0c\u4e26\u4e14\u5c07<strong class=\"final-path\">file-upload-example.php<\/strong>\u4e0a\u50b3\u81f3\u4e3b\u6a5f\u3002(\u8acb\u81ea\u884c\u900f\u904eftp\u6216\u5f8c\u53f0\u6a94\u6848\u7ba1\u7406\u54e1\u6aa2\u67e5\uff0c\u8cc7\u6599\u593e\u8207\u6a94\u6848\u662f\u5426\u5df2\u7d93\u5728\u4e3b\u6a5f\u4e0a\u4e86\u3002)\n\n\u7136\u5f8c\u5230WordPress\u5f8c\u53f0\u7684\u5df2\u5b89\u88dd\u5916\u639b\u4e2d\uff0c\u555f\u7528<strong class=\"final-path\">file-upload-examp<\/strong>\u9019\u500b\u5916\u639b\uff1a\n\n<a href=\"https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2021\/11\/VSCode-WordPressDevelopmentDirectory-2.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-17923\" src=\"https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2021\/11\/VSCode-WordPressDevelopmentDirectory-2.png\" alt=\"\" width=\"1242\" height=\"797\" \/><\/a>\n\n<div><\/div>\n\n<div><\/div>\n\n<div>\n\n<hr \/>\n\n<\/div>\n\n<div>\u555f\u7528\u5f8c\uff0c\u9019\u500b\u6e2c\u8a66\u5916\u639b\u5df2\u7d93\u5728\u8a2d\u5b9a\u4e0b\u589e\u52a0\u4e86\u4e00\u500b\u529f\u80fd\u9078\u9805&#8221;File Upload Example&#8221;\uff1a<\/div>\n\n<div><\/div>\n\n<a href=\"https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2021\/11\/VSCode-WordPressDevelopmentDirectory-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-17924\" src=\"https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2021\/11\/VSCode-WordPressDevelopmentDirectory-3.png\" alt=\"\" width=\"1063\" height=\"675\" \/><\/a>\n\n<div><\/div>\n\n<div><\/div>\n\n<div>\n\n<hr \/>\n\n<\/div>\n\n<div>\u6700\u5f8c\uff0c\u9019\u500b<span style=\"font-size: 18pt\"><a href=\"https:\/\/github.com\/flacoman91\/wordpress-demos\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/flacoman91\/wordpress-demos<\/a><\/span>\u653e\u7f6e\u4e86\u8a31\u591a\u4e0d\u932f\u7c21\u77ed\u7684WordPress\u5916\u639b\u7bc4\u4f8b\u4f9b\u6211\u5011\u4f7f\u7528\u8207\u5b78\u7fd2\u3002<\/div>\n\n<div><\/div>","protected":false},"excerpt":{"rendered":"<p>\u5728\u9019\u88cf\uff0c\u6211\u505a\u4e86\u4e00\u500b\u52d5\u4f5c\uff0c\u70ba\u4e86\u65b9\u4fbf\u6e2c\u8a66\u958b\u767cWordPress\u7684\u5916\u639b\u8207\u4e3b\u984c\uff0c\u6211\u8a2d\u7f6e\u4e86 &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","fifu_image_url":"","fifu_image_alt":"","footnotes":""},"categories":[266],"tags":[],"class_list":["post-12262","post","type-post","status-publish","format-standard","hentry","category-266"],"_links":{"self":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/12262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/comments?post=12262"}],"version-history":[{"count":1,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/12262\/revisions"}],"predecessor-version":[{"id":13357,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/12262\/revisions\/13357"}],"wp:attachment":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/media?parent=12262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/categories?post=12262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/tags?post=12262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}