How can PHP be used to output error codes for troubleshooting specific actions, such as directory creation?
To output error codes for troubleshooting specific actions like directory creation in PHP, you can use the `mkdir` function to create the directory and check if it was successful. If the directory creation fails, you can use `error_get_last()` function to retrieve the last error that occurred and output the error code.
$dir = 'path/to/directory';
if (!mkdir($dir, 0777, true)) {
$error = error_get_last();
echo "Error code: " . $error['type'];
}
Related questions
-
PHP object creation class
-
target attribute PHP forms security vulnerability
-
PHP arrays regular expressions