以下是我的php代码:(请注意,我不想在Ajax或使用任何插件中完成此操作
<?php
if(isset($_POST['edit'])){
if( $_FILES['picture']['error'] === UPLOAD_ERR_OK ) {
require_once(ABSPATH . 'wp-admin/includes/image.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/media.php');
$upload_overrides = array( 'test_form' => false ); // if you don’t pass 'test_form' => FALSE the upload will be rejected
$r = wp_handle_upload( $_FILES['picture'], $upload_overrides );
update_user_meta( $user_id, 'logo', $r );
}
}
?>
以下是我的HTML代码:
<form action="" method="POST" enctype="multipart/form-data">
<label>Upload your logo</label>
<input type="file" name="picture" id="logo" class="form-control" style="padding:0px;">
<button name="edit" type="submit" id="sub" value="submit">Update Information</button>
</form>
还请注意,我将所有注册为作者角色的人都放置在网站上。 (不知道是否相关)。