PHP filemtime() returning 1969-12-31 - cant find issue
<p>I am building a cron job that scans a directory of images and resizes anything over 800 pixels wide. I also only want it to enter into the resize if the image was uploaded that day so I tried to use filemtime() but I keep getting 1969-12-31 back. </p>

<p>I have read every forum post I could find on the issue and nothing seems to work. I have tested it on my local WIN 10 machine (using xammplite) and on my production Linux machine. Both are using PHP 5.3 or better and I get the exact same result.</p>

<p>Here's a code snippet along with echos I have added to see what's going on:</p>

<pre><code>$files = scandir($_SERVER['DOCUMENT_ROOT'] . '/forum_functions/image_uploads');

$check_date = date('Y-m-d', strtotime('now'));

echo 'check date is ' . $check_date . '&lt;br&gt;';

foreach ($files as $file)   {

    if ($file != '.' &amp;&amp; $file != '..')   {

        echo 'file date is ' . date('Y-m-d', strtotime(filemtime($_SERVER['DOCUMENT_ROOT'] . "/forum_functions/image_uploads/{$file}"))) . '&lt;br&gt;';

        echo 'file is ' . $_SERVER['DOCUMENT_ROOT'] . "/forum_functions/image_uploads/{$file}" . '&lt;br&gt;';

        echo 'file exists ' . file_exists($_SERVER['DOCUMENT_ROOT'] . "/forum_functions/image_uploads/{$file}") . '&lt;br&gt;';

        if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/forum_functions/image_uploads/{$file}") &amp;&amp; $check_date == date('Y-m-d', strtotime(filemtime($_SERVER['DOCUMENT_ROOT'] . "/forum_functions/image_uploads/{$file}"))))  {
          // do resizing
           }
       }
   }
</code></pre>

<p>The first echo in the foreach loop prints 1969-12-31 for all the images</p>

<p>The second echo in the foreach correctly prints the path</p>

<p>The third echo returns true for file exists but it fails to enter the if condition because of the date being wrong.</p>

<p>I have checked for warnings in the logs and there are none, I have checked folder permissions and they are all fine.</p>

<p>I just done get it! Maybe my eyes are missing something or there's something happening I am not privy to so I could really use some advice.</p>