Page 1 of 1

Problem with touch()

Posted: Tue Jul 22, 2003 10:49 pm
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.

Posted: Tue Jul 22, 2003 10:57 pm
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);

Problem with touch()

Posted: Tue Jul 22, 2003 11:06 pm
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.

Posted: Wed Jul 23, 2003 2:30 am
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.