jump to navigation

File existency checking in PHP June 6, 2009

Posted by dilini7 in Workshop.
trackback
  1. Testing files, lets test for some existence and status of a file called text1.txt

 

<?php

 // Checking its existence

if (file_exists(“text1.txt”)) {

        echo “The file text1.txt exists!”;

}

 

// checking the status of files

if (is_readable(“text1.txt”)) {

        echo “The file text1.txt is readable”;

}

 

if (is_writeable(“text1.txt”)) {

        echo “The file text1.txt is writeable”;

}

 

if (is_executable(“text1.txt”)) {

        echo “The file text1.txt is exectuable”;

}

?>

 You probably only see “The file text1.txt exists”. If you only see this, you will need to chmod the read,write and execute settings on that file.

Comments»

1. PHAM VU DUNG - June 7, 2009

The code is easy to understand with true condition return. Here are some useful links as well:

http://au2.php.net/file_exists

http://www.w3schools.com/PHP/func_filesystem_is_readable.asp
Vu

2. sunny - June 7, 2009

hi,,could you post the output of this PHP?

Dilini - June 8, 2009

it is check wether the your file is exist or not in this case file name is text1.txt and you can cahge it according to your requirment. if that perticular file is exist it provide out put as
“The file text1.txt exists”