Skip to content

Instantly share code, notes, and snippets.

@jonathan-dejong
Created September 15, 2016 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathan-dejong/0a6a5bb110050268785dc5e3fa63be14 to your computer and use it in GitHub Desktop.
Save jonathan-dejong/0a6a5bb110050268785dc5e3fa63be14 to your computer and use it in GitHub Desktop.
Read all files of specific file type
<?php
/**
* Reads all files of a specific file type in a folder and returns them as an array.
*
*/
public function read_files() {
$uploads_directory = trailingslashit( plugin_dir_path( dirname( __FILE__ ) ) ) . 'uploads/';
$files = array_values( array_filter( scandir( $dir ), function( $file ) {
return ( pathinfo( $file, PATHINFO_EXTENSION ) != 'txt' ? false : true );
} ) );
return $files;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment