Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin

tommcfarlin/00-read-files.php Secret

Last active Sep 15, 2016
Embed
What would you like to do?
[WordPress] Read All Files of a Certain Type / Delete All Files in a Directory
<?php
public function read_files() {
$uploads_directory = trailingslashit(
plugin_dir_path( dirname( __FILE__ ) )
) . 'uploads/';
$files = array();
foreach ( glob( $uploads_directory . 'file_*.txt' ) as $file ) {
array_push( $files, $file );
}
return $files;
}
<?php
public function delete_all_files() {
$directory = trailingslashit( $uploads_directory );
$files = glob( $directory . '{,.}*', GLOB_BRACE );
foreach ( $files as $file ) {
if ( is_file( $file ) ) {
unlink( $file );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.