[wordpress][error][solution] filemtime or filectime gives 1293858000 (i.e. 01-01-1970 05:00:00)

01 Nov

It takes hours to debug the issue i faced while listing all the files (residing in nested set of directories) with file’s last modified date and file size. It displays 01-01-1970 05:00:00 as a last modified date for all the files and empty file size. I was coding wordpress plugin and the issue arises there. When i paste the code in custom php file it works fine and get correct last modified date and size.
File path was correct as i could see the file content and filename correctly, then whats the magic behind that static date and empty size.

It was all about relative and absolute path.

I was getting file last modified date by filemtime($filename) and file size by filesize($file).
I just make the file path absolute by concatenating complete physical path before $filename as file last modified date by filemtime($physical_path.$filename) and file size by filesize($physical_path.$file).
And alhamdullilah it gets functional 🙂

Note: In most of the cases when built-in function is not correctly displaying the result then ist of all print $_SERVER[‘SCRIPT_FILENAME’]; to check out the path of the executed code (as in wordpress, code in plugin binded by admin related hooks is get called by specific file within wp-admin directory, so specially in wordpress every hook is called by its own file so for relative path one should need to know that particular file or have to use absolute path)

Leave a comment

Posted by on November 1, 2011 in wordpress


Tags: , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: