Home > Mobile >  get content of the last modified file of a directory as txt in php
get content of the last modified file of a directory as txt in php

Time:09-10

consider this is my directory and has multiple .txt file $Directory = './downloads';

I want to store the content of last modified file in the directory to a variable or something like that. that I can use somewhere else as a txt file

$Directory = './testlog'; $downloads = scandir($Directory , 1); $reportFile = $filesInTestLog [0] ; $finalReportFile = $reportFile . '.txt';

but it just pick the name of the file not the content`

CodePudding user response:

You need to read the files from the directory and check which file has the newest modification time with function filemtime(), then read the content of the file and store it as a variable.

I think that is somehow the simplest way of approaching this.

  • Related