>
Inspecting File Permissions using PHP Functions
Welcome, Guest

by vineet on Tuesday, 09 December 2008
Inspecting File Permissions using PHP Functions


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 :

$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.";
}
 

 

 

 

 



Blogger Image
My Blog Title

Product Engineering, software engineering company, Product Development, Product Migration, Product Re-engineering, Product Maintenance, Product Testing Commercial Application Development, Business Software development, commercial software for startups, Application Support and Maintenance, software testing Product Maintenance, Outsource product maintenance, product support and maintenance Product Migration, Product Re-engineering, product re-engineering services Product Research, Product Engineering, UI Prototyping Services Software Testing Services, Quality Assurance services, professional software testers, Load Testing, Functional Testing, Cross Platform, Browser Testing, Test Automation, Testing Tools, software quality analysis Functional Testing Services, software quality analysis, Software Testing Services, Application Testing Services, Functional Testing Types Automated Testing, Automated Testing Services, automation testing, test script development, Automation Test Tools, outsource automation testing Load Testing, Performance Testing Services, Load Testing Tools Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Benefits of IT Outsourcing, Offshore Software Development companies, offshore software development firms Outsource planning, IT outsourcing, IT development services, offshore IT companies, offshore software development Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering