|
|
|
| Title : |
Smart CHMOD - automagically finds the best mode for read/write purposes whether PHP is running with SuPHP or not (user nobody or equivalent). |
| Categories : |
PHP, Filesystem |
 Alix Axel |
| Date : |
Jun 19th 2008 |
| Grade : |
3 of 5 (graded 2 times) |
| Viewed : |
2656 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by Alix Axel |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
|
|
|
|
Like this code?
Show the author your appreciation.
|
| |
| <?php
function Smart_Chmod($path, $chmod = null)
{
if (is_null($chmod))
{
$user = 'nobody';
if (extension_loaded('posix'))
{
$process = posix_getpwuid(posix_geteuid());
$process['name'] = strtolower($process['name']);
if (!empty($process['name']))
{
$user = $process['name'];
}
}
if (in_array($user, array('apache', 'httpd', 'nobody', 'system', 'webdaemon', 'www')))
{
$chmod = is_dir($path) ? '0777' : '0666';
}
else
{
$chmod = is_dir($path) ? '0755' : '0600';
}
}
return chmod($path, octdec(intval($chmod)));
}
// Simply call it like this:
Smart_Chmod('/path/to/your/file.txt');
?> | | |
|
| Unix Disk Information with graphs Categories : PHP, Shell Scripting, Filesystem | | | directory, opendir, listfiles, files in a directory, get directory Categories : PHP, Filesystem | | | Show Source with Line Numbers Categories : PHP, Regexps, Filesystem | | | PHP based Contact email form with multiple recipients, text file based, supports departments. Categories : PHP, Email, Beginner Guides, Filesystem | | | How to find the name of the current file? Categories : PHP, Filesystem, Strings | | | Opening and formatting text files into HTML on the fly- or HTML from templates. Categories : PHP, HTML and PHP, Filesystem | | | Image Browser Categories : Filesystem, GD image library, Content Management, PHP | | | Differences between two files Categories : PHP, Filesystem, Tip | | | Fetching product details from the commission junction website using php Categories : PHP, FTP, Filesystem, Compression | | | Single-file PHP news system with automatic folder structure creation Categories : PHP, Filesystem, Arrays | | | Random Image Display Categories : PHP, Filesystem, Graphics, HTML and PHP | | | A PHP Script that shows how to use FTP to run a shell script, read two local files and update data in a database. Categories : PHP, Filesystem, FTP, Date Time, Databases | | | Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP, PHP, HTML, PDF, Excel | | | Read DPI value from image with PHP Categories : PHP, Graphics, Filesystem | | | Handle multiple file upload Categories : Complete Programs, Filesystem, PHP, HTML and PHP | |
| |
| |
|