Delete a File
Deletes one existing file only after realpath() confirms it is a file under an approved base directory.
Open SnippetPractical pure PHP patterns that are easy to study, adapt and use.
Deletes one existing file only after realpath() confirms it is a file under an approved base directory.
Open SnippetCopies one file from an approved source directory to an approved destination directory without overwriting existing files unless explicitly allowed.
Open SnippetRenames or moves a file inside an approved base directory after checking the source file, destination directory, overwrite rule, and path boundaries.
Open SnippetCompares isset(), empty(), and array_key_exists() across common values so missing keys, nulls, zeroes, and blank strings are handled intentionally.
Open SnippetCaptures var_dump() output for a value so type and structure details can be reviewed during development without leaking debug text to normal page output.
Open SnippetUses print_r() with return capture to produce readable array or object inspection text during controlled development debugging.
Open SnippetSets an allowed HTTP response code with http_response_code() after validating the code against a small explicit allowlist.
Open SnippetReads HTTP request headers from getallheaders() when available or from server variables using explicit HTTP header key conversion.
Open SnippetModifies a DateTimeImmutable value with an explicit timezone and returns original and adjusted dates without mutating the original value.
Open SnippetDemonstrates heredoc syntax for readable multi-line strings with variable interpolation and returns a trimmed message body.
Open SnippetDemonstrates nowdoc syntax for literal multi-line strings where dollar signs and variable-looking text remain unchanged.
Open SnippetCreates a small XML document with SimpleXMLElement, adds child nodes and attributes, and returns the XML string.
Open Snippet