Php determining whether a file exists _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.