get array of files in uploads dir


We created a frontend user profile, where the user can upload files to a special directory in wp-content/uploads/

The upload is done with a plugin called ultimate member (there it will create a special directory for every userupload (directoryname = user ID).

For example, we want to have the ability, that the user can upload mp3 tracks to his profile and the can be played there…

$upload_dir = wp_upload_dir();
$user_id = get_current_user_id();
$upload_to = $upload_dir['baseurl'] . '/ultimatemember/' . $user_id;
// echo $upload_to;
echo list_files( $upload_to );

List Files creates an error where it says function does not exist, does anyone has another idea how to get those files`?

For security reasons, it would be nice if someone can tell me the way which is the safest…

I also tried glob(), but its returning an empty array…

  // Abfragen der aktuellen Profil ID
  $profile_id = um_profile_id();
  um_fetch_user( $profile_id );

$url = get_home_url() . '/wp-content/uploads/ultimatemember/' . $profile_id .'/';
$files = glob( $url . '*' );

// print_r($files);

foreach ( $files as $file ) {
    $str = $file . basename( $file );
    echo $str;
    echo do_shortcode('' . $str . '');
LovinQuaQua 3 years 2019-10-21T11:05:15-05:00 0 Answers 57 views 0

Leave an answer