search - How to add a recent file with a .zip file extension, in a specified folder to a php variable? -


i script in php code search specific folder added file .zip file extension , add variable manipulated later.

use scandir files in specific folder, isolate zip files using strpos() or regexp on retrieved filenames. if needed, test last modification time of zip files found.

edit: using glob() faster match *.zip files.

[edit] managed come code think coded dirty. way clean up?

$show = 2; // change 0 listing found file types $dir = ''; // blank if folder/directory scanned current 1 (with script)  if($dir) chdir($dir); $files = glob( '*.zip'); usort( $files, 'filemtime_compare' );  function filemtime_compare( $a, $b ) { return filemtime( $b ) - filemtime( $a ); }  $i = 0; foreach ( $files $file ) { ++$i; if ( $i == $show ) break; $value = $file; } echo "this file name in variable: " . $value;  ?> 


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -