0

I am working on a php code as shown below in which I want to display modified date and time of all files from a directory(outgoing_folder).

$destination = 'outgoing_folder';  
$mp3_files = preg_grep('/^([^.])/', scandir($destination)); /* Line#Z */
print_r($mp3_files);  /* Line#X */

Line#X print the following:

Array ([2] => 36017P.mp3 [3] => 36031P.mp3 [4] => hello.mp3)

I have used Line#Z at Line#A and Line#B in order to display the modified date and time of all files from the directory.

<?php   foreach ($mp3_files as $file ) :  ?>  /* Line #A */
<tr>
   <td style="width:8%; text-align:center;"> <?php echo basename($file, ".mp3"); ?></td>
   <td style="width:8%; text-align:center;"><?php echo date("F d Y",filemtime("$file")); ?></td>   /* Line #B */
</tr>
<?php
   endforeach;
?>

Line#B display the following o/p (which is not the modified date and time of files):

Date 
December 31 1969
December 31 1969
December 31 1969

Problem Statement:

I am wondering what changes I need to make in the php code at Line#B so that I am able to retrieve modified date and time of all the files in a directory.

flash
  • 1,455
  • 11
  • 61
  • 132
  • Directory path maybe? `` – AbraCadaver May 15 '19 at 19:39
  • @AbraCadaver Although, it worked. I am wondering why did you use `outgoing_folder/` ? As Line#Z has already `outgoing_folder`. – flash May 15 '19 at 19:50
  • No your array `Array ([2] => 36017P.mp3 [3] => 36031P.mp3 [4] => hello.mp3)` has only the filnames not the directory so how does `filemtime` know where they are? If you use `glob` instead of `scandir` it will save the path in the array. – AbraCadaver May 15 '19 at 19:58
  • @AbraCadaver It worked thanks ! – flash May 16 '19 at 20:27

0 Answers0