admin管理员组文章数量:1122832
I am using wp_handle_upload
to upload files from a theme template file.
if ( ! function_exists('wp_handle_upload') ) require_once( ABSPATH . 'wp-admin/includes/file.php' );
$uploadedfile = $_FILES['attachedfile'];
$upload_overrides = array( 'test_form' => false );
$movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
if ( $movefile ) {
//echo "File is valid, and was successfully uploaded.\n";
//var_dump( $movefile);
$attachedfilelink=$movefile['url'];
}
I want to create a folder inside root / uploads directory with user name of who is uploading and upload the file inside the folder.
Any help ?
I am using wp_handle_upload
to upload files from a theme template file.
if ( ! function_exists('wp_handle_upload') ) require_once( ABSPATH . 'wp-admin/includes/file.php' );
$uploadedfile = $_FILES['attachedfile'];
$upload_overrides = array( 'test_form' => false );
$movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
if ( $movefile ) {
//echo "File is valid, and was successfully uploaded.\n";
//var_dump( $movefile);
$attachedfilelink=$movefile['url'];
}
I want to create a folder inside root / uploads directory with user name of who is uploading and upload the file inside the folder.
Any help ?
Share Improve this question edited Aug 28, 2013 at 13:08 birgire 67.8k7 gold badges119 silver badges251 bronze badges asked Aug 28, 2013 at 12:57 sureshsuresh 11 silver badge1 bronze badge1 Answer
Reset to default 0This isn't a working example but should help,
Use wp_upload_dir()
to define the default uploads folder and append a username to it using wp_get_current_user
.
$wp_upload_dir = wp_upload_dir();
$user_folder = wp_get_current_user();
// The actual folder
$custom_upload_folder= $wp_upload_dir['basedir'] . $user_folder->display_name;
//make the dir
mkdir($custom_upload_folder);
You would need to employ security and code that checks for errors/user capabilities and sets the correct file/folder permissions. Also have a look at https://codex.wordpress.org/Filesystem_API which employs mkdir
.
本文标签: phpCreate new folder and upload files to custom folder via wphandleupload
版权声明:本文标题:php - Create new folder and upload files to custom folder via wp_handle_upload 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736294554a1929382.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论