Php checks whether a file exists. Php is very easy to determine whether a file exists in php. you only need a function: file_exists (file path). This function is generally used to determine whether a file exists, however, it is very easy for php to determine whether a file exists in php. it only needs a function: file_exists (file path). This function is generally used to determine whether a file exists and then perform operations, commonly used file deletion: unlink (file path );
Php Tutorial to determine whether a file exists
Php is actually very easy to determine whether a file exists. only one function is required: file_exists (file path );
This function is generally used to determine whether a file exists and then perform operations. commonly used methods include deleting a file: unlink (file path );
If (file_exists ("data.txt "))
{
Print ("This file exists"); // The file exists
Print (fileinode ("data.txt "));
}
Else
{
Print ("file does not exist"); // The file does not exist
}
Method 2
If ($ submit = ""){
$ File_up = $ _ post [files];
If (file_exists ($ file_up )){
Echo "file already exists !! ";
} Else {echo "this file does not exist !! ";}
}
?>
Method 3
$ Filename = './d243375_0.png ';
$ Filename = realpath ($ filename );
If (! File_exists ($ filename )){
Die ("The image does not exist ~! ");
}
$ Size = getimagesize ($ filename );
$ File_extension = strtolower (substr (strrchr ($ filename, "."), 1 ));
If ("image/png "! = $ Size ['Mime '] | $ file_extension! = "Png "){
Die ("This is not a complete png image ");
}
$ Img = @ imagecreatefrompng ($ filename );
If ($ img ){
Ob_start ("output_handler ");
Imagepng ($ img );
Ob_end_flush ();
} Else {
Die ("You cannot create a png image correctly. Please check whether the png image is in good condition ~ ");
}
Function output_handler ($ img ){
Header ('content-type: image/png ');
Header ('content-length: '. strlen ($ img ));
Return $ img;
}
?>
Checking whether a file exists in php is actually very easy. you only need a function: file_exists (file path). This function is generally used to determine whether a file exists. however...