使用函数wp\\u handle\\u upload()
文档就是一个示例:
https://codex.wordpress.org/Function_Reference/wp_handle_upload
示例:
<form class="user_upload_photo none" enctype="multipart/form-data" action="" method="POST">
<?php wp_nonce_field(\'my_file_upload\', \'fileup_nonce\'); ?>
<input class="file_input_text" name="my_file_upload" type="file" />
<input class="btn" type="submit" value="Загрузить файл" />
</form>
处理程序:
if (wp_verify_nonce($_POST[\'fileup_nonce\'], \'my_file_upload\')) {
if (!function_exists(\'wp_handle_upload\'))
require_once( ABSPATH . \'wp-admin/includes/file.php\' );
$file = &$_FILES[\'my_file_upload\'];
$overrides = array(\'test_form\' => false);
$movefile = wp_handle_upload($file, $overrides);
if ($movefile) {
echo "File downloaded";
} else {
echo "when the file download error";
}
}