search for in the  
<tmpfileumask>
Last updated: Thu, 19 May 2005

touch

(PHP 3, PHP 4, PHP 5)

touch -- Sets access and modification time of file

Description

bool touch ( string filename [, int time [, int atime]] )

Attempts to set the access and modification time of the file named by filename to the value given by time. If the parameter time is not given, uses the present time. This is equivalent to what utime (sometimes referred to as utimes) does. If the third parameter atime is present, the access time of the given filename is set to the value of atime. Note that the access time is always modified, regardless of the number of parameters.

If the file does not exist, it is created. Returns TRUE on success or FALSE on failure.

Example 1. touch() example

<?php
if (touch($FileName)) {
   echo
"$FileName modification time has been changed to present time";

} else {
   echo
"Sorry, could not change modification time of $FileName";

}
?>



User Contributed Notes
touch
guy at forster design dot com
12-May-2005 05:42
Here's a little workaround that allows the PHP user to touch a file it doesn't own:

<?php

   $target_file
= "/path/to/file/filename.txt"; //system filepath to your file
  
$file_content = implode("",file($target_file));
   @
unlink($target_file);
   if(
$savetofile = fopen($target_file, "w")) {
      
fputs($savetofile, $file_content);
      
fclose($savetofile);
   }
  
$new_date = strtotime("23 April 2005"); // set the required date timestamp here
  
touch($target_file,$new_date);
 
?>

Of course, PHP needs to have write access to the folder containing the file you want to touch, but that should be easy to arrange.
feathern at yahoo dot com
13-Aug-2002 05:31
Neat little script that will give you a list of all modified files in a certain folder after a certain date:

$filelist = Array();
$filelist = list_dir("d:\\my_folder");
for($i=0;$i<count($filelist);$i++){
   $test = Array();
   $test = explode("/",date("m/d/Y",filemtime($filelist[$i])));
//example of files that are later then
//06/17/2002
   if(($test[2] > 2001) && ($test[1] > 16) && ($test[0] > 5)){
       echo $filelist[$i]."\r\n";
   }
   clearstatcache();
}
function list_dir($dn){
   if($dn[strlen($dn)-1] != '\\') $dn.='\\';
   static $ra = array();
   $handle = opendir($dn);
   while($fn = readdir($handle)){
       if($fn == '.' || $fn == '..') continue;
       if(is_dir($dn.$fn)) list_dir($dn.$fn.'\\');
       else $ra[] = $dn.$fn;
   }
   closedir($handle);
   return $ra;
}
emilebosch at hotmail dot com
06-Oct-2001 05:41
To spare you ppl couple of hours of valuable time, you can only TOUCH a file that you own! Usually PHP is *nobody*
Warm regards,
Emile Bosch
master at dreamphp dot com
15-May-2001 01:23
$filename = "test.dat";
if (!file_exists($filename)) {
  touch($filename); // Create blank file
  chmod($filename,0666);
}

<tmpfileumask>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 17:35:34 2005 CDT