Demonstrates core file I/O operations using the File class.
- Creating a file with
create(), including automatic parent directory creation viacreate(true) - Writing content with
write(false)(override mode) andwrite(true)(append mode) - Reading file content back with
read()andgetRawData() - Creating and writing in a single step with
write(true, true)(the secondtruecreates the file if it doesn't exist) - Removing a file with
remove()
File::create(bool $createDirIfNotExist = false)— Creates the file on disk. Passtrueto also create missing parent directories.File::setRawData(string $raw)— Sets the in-memory content to be written.File::write(bool $append = true, bool $createIfNotExist = false)— Writes raw data to the file. First parameter controls append vs override. Second parameter creates the file if missing.File::read()— Reads the file content into memory.File::getRawData()— Returns the in-memory content as a string.File::remove()— Deletes the file from disk.
php examples/read-and-write.php