iPhone Remote Debugger

Jon Brisbin is a Java programmer doing iPhone development, and decided to scratch his own itch for a better iPhone remote debugger, creating iPhoneDebug: The iPhone Debug Consle is meant to give greater visibility and interactivity on your iPhone/...

Inspecting File Permissions using PHP Functions Print E-mail
User Rating: / 10
PoorBest 

PHP Interpreter can read or write files on which it have permission to do so.  PHP provides few functions using those we can easily check the status of permission assigned on any file. These functions are useful, if we are going to manipulate files in our program. Here, are we will see usages of such functions in practical way.

 

Checking existence of File

We can check any file existence using   file_exists()   function. This function is easy to use and take file name as an value and returns true or false depending on the availability of file in that particular directory. Here is an example:

 

if (file_exists('/home/user1/readfile.txt')) {
print "readfile.txt is in directory";
} else {
print "No such file exists";
}

 

Checking read and write permission on File

To check read permission on any file, we can use is_readable() and to check write permission, the function is is_writeable(). Below are examples :

 

Read permission check:

$my_log_file = "log_file.dat";

if (is_readable($my_log_file)) {
$read_logs = file_get_contents($my_log_file);
} else {
print "Cannot read log file for processing";
}

 

Write permission check:

$my_log_file = "log_file.dat";

if (is_writeable($my_log_file)) {
$file_handle = fopen($my_log_file, 'ab');
fwrite($file_handle, 'User '.$_SESSION['user_name'].' at '.strftime('%c')."\n");
fclose($file_handle);
} else {
print "Cannot write to log file. Please check permissions first.";
}
 
< Prev   Next >