Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

filemtime retrieving incorrect date

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

filemtime retrieving incorrect date

Postby Gina » Thu Apr 10, 2003 12:10 pm

I am trying to display a last modified date on a file. The file is uploaded to the server and then loaded into a mysql database. Since I keep a copy of the uploaded file, I thought it would be easiest to grab the date of the newest uploaded file.

The date retrieved is December 31 1969. I have no idea where this date is coming from.

I was using
Code: Select all
filemtime($file),
but read something about Apache not displaying this correctly and to use
Code: Select all
filemtime($_SERVER["SCRIPT_$file"])
Either way the date is still December 31 1969.

Here is the script
Code: Select all
$current_dir="/sqldata/";
$file=basename($upz5In0001.txt);
$file=$current_dir.$file;
echo "File last modified: " .date("F j Y", filemtime($_SERVER["SCRIPT_$file"]))."<br>";


Any ideas?

Thanks,
Gina
Gina
New php-forum User
New php-forum User
 
Posts: 3
Joined: Thu Oct 31, 2002 7:51 am

Postby pootergeist » Fri Apr 11, 2003 12:49 am

$file=basename($upz5In0001.txt);

why the $ in there?

if you want to concatenate a var-text string use quotes

basename($upz.'51n0001.txt');

either way - Dec 31 '69 is effectively zero as a unixtimestamp (or minus one to be exact - though nixtime doesn't natively use negatives)
pootergeist
New php-forum User
New php-forum User
 
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK

Postby Gina » Fri Apr 11, 2003 5:11 am

I think that was a mistake on my part, the $ shouldn't be in front of the file name.

$file=basename($upz5In0001.txt);

I removed the $ and added quotes. Then realized that the file was not being found.

This was looking for the file from the server root
$current_dir="/sqldata/";

I changed it to
$current_dir="./sqldata/";
then the file was found correctly and the last modified date showed properly.

I guess I was getting the 1969 date because there was no file there which would make the date zero.


Thanks for your help.

Gina
Gina
New php-forum User
New php-forum User
 
Posts: 3
Joined: Thu Oct 31, 2002 7:51 am


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot], Google Feedfetcher and 6 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.