Support » Plugin: Really Simple CSV Importer » audio file not playing in acf custom field

  • I am uploading the audio file in custom field upload is fine when CSV file uploading done they don’t play WordPress media and frontend can you guide me furthermore what happen to me see my below code:

    
    <?php
    add_filter( 'really_simple_csv_importer_save_meta', 'rsc_import_images',10,3);
    function rsc_import_images( $meta, $post, $is_update ) {
      $audioFiles = $meta['cfs_audio_file'];
    
      //directory to import audioFiles to
      $artDir = 'wp-content/uploads/audio_file/';
    
      //if the directory doesn't exist, create it
      if(!file_exists(ABSPATH.$artDir)) {
        mkdir(ABSPATH.$artDir);
      }
      require_once(ABSPATH . 'wp-load.php');
      require_once(ABSPATH . 'wp-admin/includes/image.php');
      global $wpdb;
    
        //let's get the image file name
        $new_filename = end(explode(".", $audioFiles));
       
        //move the file to our custom import folder
        if (!@fclose(@fopen($audioFiles, "r"))) { //make sure the file actually exists
          $siteurl = get_option('siteurl');
          @$auduploadfile =  basename( $audioFiles );
          $audfilename = basename( $auduploadfile );
        $audFileType = pathinfo($audfilename,PATHINFO_EXTENSION);
          $wp_filetype = wp_check_filetype(basename($audfilename), null );
         
          //create an array of attachment data to insert into wp_posts table
          $artdata = array(
            'post_author' => 1,
            'post_date' => current_time('mysql'),
            'post_date_gmt' => current_time('mysql'),
            'post_title' => sanitize_file_name($audfilename),
            'post_content' => sanitize_file_name($audfilename),
            'post_status' => 'inherit',
            'comment_status' => 'closed',
            'ping_status' => 'closed',
            'post_name' => sanitize_title_with_dashes(str_replace("_", "-", sanitize_file_name($audfilename))),
            'post_modified' => current_time('mysql'),
            'post_modified_gmt' => current_time('mysql'),
            'post_type' => 'attachment',
            'guid' => $siteurl.'/'.$artDir.$audfilename,
            'post_mime_type' => $wp_filetype['type']
          );
          
          $uploads = wp_upload_dir();
          $save_path = $uploads['basedir'].'/audio_file/'.$audfilename;
    
          //insert the database record
          $attach_id = wp_insert_attachment( $artdata, $save_path );
          
          $meta['cfs_audio_file']= $attach_id;
          
          
        }
      
    
      return $meta;
    }
    
    
  • The topic ‘audio file not playing in acf custom field’ is closed to new replies.