-
-
Save tommcfarlin/05ca730f85a7ca31471017de7b4eadc4 to your computer and use it in GitHub Desktop.
[WordPress] Read All Files of a Certain Type / Delete All Files in a Directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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