Problem with touch()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
msbask
Forum Newbie
Posts: 2
Joined: Tue Jul 22, 2003 10:49 pm

Problem with touch()

Post by msbask »

I am able to use the following code to set $filename to the current time:

touch($filename) // SET TO CURRENT DATE/TIME

However, I would like to set $filename to another date, such as April 1, 2002 but cannot seem to get the syntax correct:

touch($filname, "20020104") // DOES NOT WORK

Any help is appreciated.
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

Touch() entry in PHP manual is kind of vague, but I don't think the second argument is in that format (YYYYMMDD). Try a unix timestamp instead:

$time = time();
touch ("file.ext",$time);
msbask
Forum Newbie
Posts: 2
Joined: Tue Jul 22, 2003 10:49 pm

Problem with touch()

Post by msbask »

Unfortunately, that doesn't work either.

Here's code that DOES works:

$filename = "construct.jpg";
if (touch($filename))
{
echo "FILE DATE CHANGED";
}

Here's code that DOES NOT work:

$filename = "construct.jpg";
$time = time();
if (touch($filename,$time))
{
echo "FILE DATE CHANGED";
}

I need to be able to set a filedate to a specific date, but can't even seem to get the above function to work.

Thanks again for any help.
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

if you work on a unix based system try to use the touch command of the shell.

$Cmd="touch 20031111 ".$file; system($Cmd);

something like that.

type "man touch" into a terminal for details.
Post Reply