* Find all files in a given directory, including files within subfolders (and their subfolders, etc.) */
( $dir )
| 258 | * Find all files in a given directory, including files within subfolders (and their subfolders, etc.) |
| 259 | */ |
| 260 | function files_in_dir_deep( $dir ) { |
| 261 | $files_and_dirs = glob( rtrim( $dir, '/' ) . '/' . "*" ); |
| 262 | |
| 263 | $files = array(); |
| 264 | |
| 265 | foreach ( $files_and_dirs as $file_or_dir ) { |
| 266 | if ( file_exists( $file_or_dir ) ) { |
| 267 | if ( is_file( $file_or_dir ) ) { |
| 268 | $mime_type = mime_content_type( $file_or_dir ); |
| 269 | |
| 270 | if ( stripos( $mime_type, 'video/' ) === 0 ) { |
| 271 | $files[] = $file_or_dir; |
| 272 | } |
| 273 | } else { |
| 274 | $files = array_merge( $files, files_in_dir_deep( $file_or_dir ) ); |
| 275 | } |
| 276 | } else { |
| 277 | echo "File does not exist: " . $file_or_dir . "\n"; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | return $files; |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Find the duration in seconds of a given video file. |