Sunday 4 April 2010

How to check if a file exists in your Web Server!

One thing I came across which was quite interesting was to check if a file exists before we do any operation on the file itself.

We do that by using a php function and we do that by:

if (file_exists('file.txt')) {
print 'OK, file.txt exists.';
}

Alright this is pretty much self-explanatory, here what we are doing is checking if the file exists or not. And if does, we simply print the message. You can simply use this function in your programs before working with the file otherwise this might throw an error if the file doesn't exists.

Very simple!

No comments :