touch

Sets access and modification time of file

Syntax

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

Parameters

filename

The name of the file being touched.

time

The touch time. If time is not supplied, the current system time is used.

atime

If present, the access time of the given filename is set to the value of atime. Otherwise, it is set to the value passed to the time parameter. If neither are present, the current system time is used.

Return

Returns TRUE on success or FALSE on failure.

Examples

1

<?

$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

<?

$filename = $_SERVER['DOCUMENT_ROOT'];
$time = time() - 3600;

if (touch($filename, $time)) {
    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

<?

$filename = $_SERVER['DOCUMENT_ROOT'];
$time = time() - 3600;
$atime = time() - 7200;

if (touch($filename, $time, $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

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

PHP

Home Menu