wp filesystem - How to Copy Upload Image using WP_Filesystem_Direct

I'm trying to export post_type and its attached image. However, I'm stacking at copying file to export directo

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 );

            }


        }


    }

}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744661960a4586510.html

相关推荐

  • wp filesystem - How to Copy Upload Image using WP_Filesystem_Direct

    I'm trying to export post_type and its attached image. However, I'm stacking at copying file to export directo

    1天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信