Error handling function in PHP. Its purpose is to print a message and exit the current php script. It’s the PHP equivalent of the exit() function. Error handling is the process of detecting and responding to errors raised by your program. If you don’t handle errors properly, they can have a lot of unintended consequences.
if( !file_exists("inlarn.txt") )
die("File is not present");
$file = fopen("inlarn.txt", "w");
Die in PHP
PHP has a built-in function called die(). Its purpose is to print a message and exit the current php script. It’s the PHP version of the exit() function.
Files in PHP
$_FILES is a two-dimensional associative global array containing things being uploaded using the HTTP POST method, and it contains file attributes such as: Attribute. Description. [name] The name of the file that is being uploaded.
fopen in PHP and How it Works in Error handling function in PHP
The fopen function opens and associates a file named filename with stream. The fopen function clears the stream’s error and EOF indicators. The fopen() function in PHP is a built-in function for opening a file or URL. It’s used to attach a resource to a steam by specifying a filename.
The fopen() function is passed the filename and mode to be examined as inputs, and it returns a file pointer resource if a match is discovered and False otherwise. By placing a ‘@’ in front of the function name, the error output can be hidden.
If Else Statement in PHP