php - How to find latest last modified directory on ftp -
i developing application in php. there lots of file handling. want last modified folder on ftp. getting last modified file. want file last modified folder also.
my code
$ftp_server='xxxxxxx'; $ftp_user_name='xxxxxxxx'; $ftp_user_pass='xxxxxxxx'; $conn_id = ftp_connect($ftp_server); $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); if ((!$conn_id) || (!$login_result)) { echo "ftp connection has failed!"; echo "attempted connect $ftp_server user $ftp_user_name"; exit; } else {} $folder= ftp_pwd ( $conn_id ); ftp_pasv($conn_id, true); $get_folder_namesss = ftp_nlist($conn_id, '.'); $folder_name = array() ; $local_file=''; $folder = '/abc/def/ghi/2014/02/'; $handle=''; $time=''; $handle1=''; $files = ftp_nlist($conn_id, $folder); if (!count($files)) { echo "folder empty"; return false; } $mostrecent = array ( 'time' => 0, 'file' => null ); foreach ($files $file) { if (!preg_match('~\w+.xls$~ism', $file)) continue; $time = ftp_mdtm($conn_id, $file); echo "$file last modified on : " . date("f d y h:i:s.", $time); if ($time > $mostrecent['time']) { $mostrecent['time'] = $time; $mostrecent['file'] = $file; } } $local_file = '../ftp/'.basename($mostrecent['file']); if (file_exists($local_file)) {} else { $handle = fopen($local_file, 'w'); if (ftp_fget($conn_id, $handle, $mostrecent['file'], ftp_ascii, 0)) {} else { return "there problem while downloading ".$mostrecent['file']." $local_file\n"; } fclose($handle); $handle1 = fopen($local_file,"r"); $t=1; $vales = array(); while (($data = fgetcsv($handle1, 1000, ",")) !== false) { $num = count($data); ($c=0; $c < $num; $c++) { $vales[$t]=$data[$c] ; $t++; } } fclose($handle1); }
$folder = '/abc/def/ghi/2014/02/';
folder path. last 2 folder year , month. there many folder 2011,2012,2013,2014 sorted year wise. want find latest folder , 2014. please suggest. thanks.
you can folder created time use of stat function.
$folder = stat('/abc/def/ghi/2014/02/'); echo 'modification time: ' . $folder['mtime']; // show unix time stamp.
please try can able this
Comments
Post a Comment