该函数指定了uploads的目录为uploads的avatar文件夹:
代码如下 | 复制代码 |
function my_upload_dir($upload) { $upload['subdir']= '/avatar'; $upload['path']= $upload['basedir'] . $upload['subdir']; $upload['url']= $upload['baseurl'] . $upload['subdir']; return $upload; } |
然后在需要改变上传路径的地方加上钩子函数:
代码如下 | 复制代码 |
//Handles PHP uploads in WordPress. add_filter('upload_dir', 'my_upload_dir'); $file_attr = wp_handle_upload( $_FILES['avatar_manager_import'], $overrides ); remove_filter('upload_dir', 'my_upload_dir'); |
当然上传图片和文件需要调用wordpress的上传图片函数
时间: 2024-10-24 20:33:55