This gets the Images from my folder.
$dirname = "./uploaded_files/";
$images = scandir($dirname);
$ignore = Array(".", "..");
foreach($images as $curimg){
if(!in_array($curimg, $ignore)) {
};
This gets the last modified dates for each file in the folder.
$result = array();
$folder = ('uploaded_files/');
$handle = opendir($folder);
foreach (glob("$folder/*") as $team){$sort[]= end(explode('/',$team));}
Making an array containing the files in the current directory:
while (false !==($file = readdir($handle)))
{
if ( $file != ".." && $file != "." )
{
$file = "uploaded_files/".$file ;
if (!is_dir($file))
$result[] = $file;
}
}
closedir($handle);
This is my IF AND FOR EACH statement (here is my problem)!!!
$lastmoddate = (date("Ymd", filemtime($file)));
$todaysdate = (date("Ymd"));
foreach ($result as $file){
if ($lastmoddate <= $todaysdate){
if (strpos($file, "+12:00") !==false){
echo "$file".",".date ("h:i d/m/Y", filemtime($file))."\r\n"."<br/>";
}
}
}
what I am trying to do is ‘if the file names contain +12:00 and if the lastmodified dates for each file is less or equal to todays date then echo Images! BUT it Doesn’t work.
Can anyone help me figure out how to re-write my statement!?
I’ve just started learning PHP
Can anyone help!?
Thanks
By using the date() function, you are converting the integer date into a human readable date. In doing this, you will no longer be able to compare the dates (in the d m y format you are using).
The easiest fix would be to change your date format from “d m y” to “Ymd” so that it can be compared as a number.
Also, you mention that the moddate should be less or equal to, but your code uses >=, so you may need to switch that around.