Jun
17
2013
				
				17
2013
Remove a directory with all contents
/**
 * Function to delete all files in a given directory
 *
 * @access public
 * @param string $directory
 * @return void
 */
function delete_files( $directory )
{
    if ( !file_exists( $directory ) )
        return false;
    if ( is_dir( $directory ) && $dir_contents = opendir( $directory ) )
    {
        while ( false !== ( $single_file = readdir( $dir_contents ) ) )
        {
            unlink( $directory . '/' . $single_file );
        }
        closedir( $dir_contents );
    }
    return rmdir( $directory );
}Leave a comment
Recent Snippets
- htaccess : Only allow access to specific wordpress upload types if logged in
- MySQL : Query WordPress Database for Invalid Media Filenames
- PHP : Get Actual IP Address with PHP
- JavaScript : Allow Tab in Textarea
- PHP : Clean sanitized database contents on output
- htaccess : Force www. prefix in URIs
- PHP : Force File Download with Correct Content Type
- Wordpress : Disable upgrade notification

 A snippet by admin
 A snippet by admin   
					 
 




