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!
Showing posts with label code. Show all posts
Showing posts with label code. Show all posts
Sunday, 4 April 2010
How to check if a file exists in your Web Server!
Labels:
code
,
mysql
,
php
,
programming
,
source code
,
sql
How to check if a variable is null in PHP!
As we were talking about various functions in PHP, one of the functions to check if the value is null is: is_null($MyVal) and here if the values is null it will return true and false if the value is not null.
You can always go for something like: !is_null($MyVal) that way, if the value is not null then do something.
Very simple and straight forward!
Ok again, leave your comment down below.
Cheers!
You can always go for something like: !is_null($MyVal) that way, if the value is not null then do something.
Very simple and straight forward!
Ok again, leave your comment down below.
Cheers!
Labels:
code
,
coding
,
mysql
,
php
,
program
,
programming
,
source code
Subscribe to:
Posts
(
Atom
)