touch
Description
The touch of Filesystem for PHP sets access and modification time of file.
Syntax
touch( string $filename, ?int $mtime = null, ?int $atime = null ): bool
Parameters
filename
The name of the file being touched.
mtime
The touch time. If mtime is null, the current system time() is used.
atime
If not null, the access time of the given filename is set to the value of atime. Otherwise, it is set to the value passed to the mtime parameter. If both are null, the current system time is used.
Return
Returns true on success or false on failure.
Examples
1 · filename
<? $filename = $_SERVER['DOCUMENT_ROOT']; if(touch($filename)) { echo 'access time and modification time set to current time'; } else { echo 'touch() failed'; } ?>
access time and modification time set to current time
2 · mtime
<? $filename = $_SERVER['DOCUMENT_ROOT']; $mtime = time() - 3600; if(touch($filename, $mtime)) { echo 'access time and modification time set to one hour in the past'; } else { echo 'touch() failed'; } ?>
access time and modification time set to one hour in the past
3 · atime
<? $filename = $_SERVER['DOCUMENT_ROOT']; $mtime = time() - 3600; $atime = time() - 7200; if(touch($filename, $mtime, $atime)) { echo 'access time set to two hours in the past and modification time set to one hour in the past'; } else { echo 'touch() failed'; } ?>
access time set to two hours in the past and modification time set to one hour in the past
4 · return
<? $filename = $_SERVER['DOCUMENT_ROOT']; $return = touch($filename); var_export($return); ?>
true
Links
Filesystem
- basename
- chgrp
- chmod
- chown
- clearstatcache
- copy
- dirname
- disk_free_space
- disk_total_space
- diskfreespace
- fclose
- feof
- fflush
- fgetc
- fgetcsv
- fgets
- file
- file_exists
- file_get_contents
- file_put_contents
- fileatime
- filectime
- filegroup
- fileinode
- filemtime
- fileowner
- fileperms
- filesize
- filetype
- flock
- fnmatch
- fopen
- fpassthru
- fputcsv
- fputs
- fread
- fscanf
- fseek
- fstat
- ftell
- ftruncate
- fwrite
- glob
- is_dir
- is_executable
- is_file
- is_link
- is_readable
- is_uploaded_file
- is_writable
- is_writeable
- lchgrp
- lchown
- link
- linkinfo
- lstat
- mkdir
- move_uploaded_file
- pathinfo
- pclose
- popen
- readfile
- readlink
- realpath
- realpath_cache_get
- realpath_cache_size
- rename
- rewind
- rmdir
- set_file_buffer
- stat
- symlink
- tempnam
- tmpfile
- umask
- unlink