Shiva Navaneeth February 2016

Set timezone to display last modified information from a directory

$headers = array("File Name", "Size", "Type", "Modified") ; 
$width = array(20, 11, 20, 11) ;                        

$info ; 

print_header() ;
foreach (glob("*") as $filename) {
  file_info($filename) ;
  print_file_info() ;
}
exit(0) ;

function file_info($name) {
  global $info ;                
    $info[0] = $name ;          
    $info[1] = filesize($name) ;  
    $info[2] = filetype($name);                            
    $info[3] = date($name);
}

Require help in setting the timezone to display the date and time under the modified section in the array "$info[3] = date($name);". I believe "date_default_timezone_set('Europe/London')" is meants to be used to set the timezone however am unsure where to input that line. It should display in the format 'Oct 20 2015 09:34' and my code seems to execute the code in the format 'f28MondayEu'.

Answers


Barmar February 2016

$info[3] = date($name);

should be:

$info[3] = filemtime($name);

This will set $info[3] to a numeric timestamp. print_file_info() needs to call date_default_timezone_set(), and then it can use the date() function to format the timestamp in the manner you want.

And to create an array, you need to initialize the variable:

$info = array();

Post Status

Asked in February 2016
Viewed 1,668 times
Voted 4
Answered 1 times

Search




Leave an answer