PHP Filesystem Reference
Separate pathname inspection, byte I/O and ownership. An existing filename is not proof that a caller may read or modify it.
How it works
Filesystem helpers have return-value, caching and race boundaries. Checking existence and opening later are separate operations, so a prior check cannot eliminate every concurrent change. Keep trusted roots, use appropriate open modes and handle failures at the operation itself. Directory enumeration also needs symlink and permission policies. The related inventory includes legacy spellings and aliases; consult the official contract before choosing one.
Run it locally
Run this complete source locally with PHP 8.2 or newer. Save it using the filename shown and run the command below. PHP is not currently available in Bhylu’s browser playground. Apache and MySQL are not needed for an ordinary CLI example.
php -l ref-files.php
php ref-files.phpDownload this source as a local PHP lab file. Keep lab files separate from the Bhylu project and production data.
Example
<?php
declare(strict_types=1);
$stream = fopen("php://temp","w+");
if ($stream === false) throw new RuntimeException("No stream");
try { fwrite($stream,"Tool note"); rewind($stream); echo stream_get_contents($stream), "\n"; } finally { fclose($stream); }
Expected result
Tool noteThe temporary stream is allocated and closed by one block. Rewinding changes its current read position. This example does not require access to a personal path or a production upload directory and does not establish the permissions of a later permanent storage design.
Contracts to check
| API or term | Important boundary |
|---|---|
| fopen, fread, fgets, fwrite, fclose | Open mode, size bounds, partial operations and ownership matter. |
| file_get_contents, file_put_contents | Whole-content convenience needs a deliberate size/overwrite policy. |
| realpath, dirname, basename, pathinfo | Path inspection is not a complete traversal or symlink defence. |
| unlink, rename, mkdir, rmdir | Mutations require a checked owned target and platform-aware failure handling. |
| DirectoryIterator, FilesystemIterator, scandir | Enumeration order and symlink treatment need a policy. |
Related API names
This alphabetic inventory helps locate related calls. Availability was checked in the review runtime; it is not a recommendation to use every API or a claim that every overload/function was executed. Read the official entry for version, extension, failure and security details.
| Name | Review-runtime status |
|---|---|
basename() | Available in the PHP review runtime |
chdir() | Available in the PHP review runtime |
chgrp() | Available in the PHP review runtime |
chmod() | Available in the PHP review runtime |
chown() | Available in the PHP review runtime |
chroot() | Not available in this review runtime; check version and extension requirements |
clearstatcache() | Available in the PHP review runtime |
closedir() | Available in the PHP review runtime |
copy() | Available in the PHP review runtime |
delete() | Not available in this review runtime; check version and extension requirements |
dir() | Available in the PHP review runtime |
dirname() | Available in the PHP review runtime |
disk_free_space() | Available in the PHP review runtime |
disk_total_space() | Available in the PHP review runtime |
diskfreespace() | Available in the PHP review runtime |
fclose() | Available in the PHP review runtime |
feof() | Available in the PHP review runtime |
fflush() | Available in the PHP review runtime |
fgetc() | Available in the PHP review runtime |
fgetcsv() | Available in the PHP review runtime |
fgets() | Available in the PHP review runtime |
fgetss() | Not available in this review runtime; check version and extension requirements |
file() | Available in the PHP review runtime |
file_exists() | Available in the PHP review runtime |
file_get_contents() | Available in the PHP review runtime |
file_put_contents() | Available in the PHP review runtime |
fileatime() | Available in the PHP review runtime |
filectime() | Available in the PHP review runtime |
filegroup() | Available in the PHP review runtime |
fileinode() | Available in the PHP review runtime |
filemtime() | Available in the PHP review runtime |
fileowner() | Available in the PHP review runtime |
fileperms() | Available in the PHP review runtime |
filesize() | Available in the PHP review runtime |
filetype() | Available in the PHP review runtime |
flock() | Available in the PHP review runtime |
fnmatch() | Available in the PHP review runtime |
fopen() | Available in the PHP review runtime |
fpassthru() | Available in the PHP review runtime |
fputcsv() | Available in the PHP review runtime |
fputs() | Available in the PHP review runtime |
fread() | Available in the PHP review runtime |
fscanf() | Available in the PHP review runtime |
fseek() | Available in the PHP review runtime |
fstat() | Available in the PHP review runtime |
ftell() | Available in the PHP review runtime |
ftruncate() | Available in the PHP review runtime |
fwrite() | Available in the PHP review runtime |
getcwd() | Available in the PHP review runtime |
glob() | Available in the PHP review runtime |
is_dir() | Available in the PHP review runtime |
is_executable() | Available in the PHP review runtime |
is_file() | Available in the PHP review runtime |
is_link() | Available in the PHP review runtime |
is_readable() | Available in the PHP review runtime |
is_uploaded_file() | Available in the PHP review runtime |
is_writable() | Available in the PHP review runtime |
is_writeable() | Available in the PHP review runtime |
lchgrp() | Not available in this review runtime; check version and extension requirements |
lchown() | Not available in this review runtime; check version and extension requirements |
link() | Available in the PHP review runtime |
linkinfo() | Available in the PHP review runtime |
lstat() | Available in the PHP review runtime |
mkdir() | Available in the PHP review runtime |
move_uploaded_file() | Available in the PHP review runtime |
opendir() | Available in the PHP review runtime |
parse_ini_file() | Available in the PHP review runtime |
parse_ini_string() | Available in the PHP review runtime |
pathinfo() | Available in the PHP review runtime |
pclose() | Available in the PHP review runtime |
popen() | Available in the PHP review runtime |
readdir() | Available in the PHP review runtime |
readfile() | Available in the PHP review runtime |
readlink() | Available in the PHP review runtime |
realpath() | Available in the PHP review runtime |
realpath_cache_get() | Available in the PHP review runtime |
realpath_cache_size() | Available in the PHP review runtime |
rename() | Available in the PHP review runtime |
rewind() | Available in the PHP review runtime |
rewinddir() | Available in the PHP review runtime |
rmdir() | Available in the PHP review runtime |
scandir() | Available in the PHP review runtime |
set_file_buffer() | Available in the PHP review runtime |
stat() | Available in the PHP review runtime |
symlink() | Available in the PHP review runtime |
tempnam() | Available in the PHP review runtime |
tmpfile() | Available in the PHP review runtime |
touch() | Available in the PHP review runtime |
umask() | Available in the PHP review runtime |
unlink() | Available in the PHP review runtime |
Check the official PHP manual for detailed version and API contracts.