admin管理员组文章数量:1391999
I'm trying to export post_type and its attached image.
However, I'm stacking at copying file to export directory.
WP_Filesystem_Direct::copy failed to open stream ( No file or directory ).
Here the bellow is my code:
if ( isset( $_POST['export'] ) ) {
if ( $_POST['export'] != 'export' ) return;
$args = array(
'post_type' => 'notebook',
'post_status' => 'publish',
'posts_per_page' => -1,
);
$notebooks = new WP_Query( $args );
if ( $notebooks->have_posts() ) {
$time = date("Y-m-d-H-i-s");
$wp_admin_path = ABSPATH . '/wp-admin';
$export_path = ltc_get_upload_path() . 'export-notebooks';
if( !class_exists( 'WP_Filesystem_Direct' ) ) {
require $wp_admin_path . '/includes/class-wp-filesystem-base.php';
require $wp_admin_path . '/includes/class-wp-filesystem-direct.php';
}
$wpsf = new WP_Filesystem_Direct( false );
if ( !$wpsf->exists( $export_path ) ) {
$wpsf->mkdir( $export_path );
}
$outstream = fopen( get_temp_dir( ) . "$time-exported-notebooks.csv", 'w');
while( $notebooks->have_posts() ) {
$notebooks->the_post();
$post_id = get_the_ID();
$attachment_id = get_post_thumbnail_id( $post_id );
$image = get_attached_file( $attachment_id );
$image_path = substr( $image, strlen( ltc_get_upload_path() ) );
$destination = $export_path ."/$image_path";
if ( $wpsf->is_file( $image ) ) { // return true
$wpsf->copy( $image, $destination );
}
}
}
}
本文标签: wp filesystemHow to Copy Upload Image using WPFilesystemDirect
版权声明:本文标题:wp filesystem - How to Copy Upload Image using WP_Filesystem_Direct 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744661960a2618295.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论