Home > Backend Development > PHP Tutorial > PHP determines whether a file exists_PHP tutorial

PHP determines whether a file exists_PHP tutorial

WBOY
Release: 2016-07-13 10:58:19
Original
1907 people have browsed it

php determines whether the file exists It is actually very simple to determine whether a file exists in PHP. It only requires one function: file_exists (file path); This function is generally used to determine whether a file exists, and then perform operations. Commonly used ones include deleting files: unlink (file path);

php tutorial to determine whether a file exists
It is actually very simple to determine whether a file exists in PHP. It only requires one function: file_exists (file path);
This function is generally used to determine whether the file exists and then operate it. Commonly used ones include deleting files: 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"); //File does not exist
}


Method 2

if($submit=="Find"){
$file_up=$_post[files];
if(file_exists($file_up)){
echo "File already exists!!";
}else{echo "The file does not exist!!";}
}
?>


Method 3

$filename = './d243375_0.png';
$filename = realpath($filename);
if (!file_exists($filename)) {
die("The picture 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 picture");
}
$img = @imagecreatefrompng ($filename);
if($img){
ob_start("output_handler");
imagepng($img);
ob_end_flush();
}else{
die("The png graphic cannot be created correctly, please check whether the png graphic is intact~");
}
function output_handler($img) {
header('content-type: image/png');
header('content-length:'.strlen($img));
return $img;
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632028.htmlTechArticlephp determines whether a file exists. php determines whether a file exists. It is actually very simple. It only requires one function: file_exists(file Path); This function is generally used to determine whether the file exists, then...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template