note 73596 added to function.is-writable
| From: | legolas558d0tusersdotsfdotnet at osu1 dot php dot net | Date: | Fri, 02 Mar 2007 20:18:11 +0000 |
| Subject: | note 73596 added to function.is-writable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124024@lists.php.net to get a copy of this message | ||
This is the latest version of is__writable() I could come up with.
It can accept files or folders, but folders should end with a trailing slash! The function attempts
to actually write a file, so it will correctly return true when a file/folder can be written to when
the user has ACL write access to it.
<?php
function is__writable($path) {
//will work in despite of Windows ACLs bug
//NOTE: use a trailing slash for folders!!!
//see http://bugs.php.net/bug.php?id=27609
//see http://bugs.php.net/bug.php?id=30931
if ($path{strlen($path)-1}=='/') // recursively return a temporary file path
return is__writable($path.uniqid(mt_rand()).'.tmp');
else if (is_dir($path))
return is__writable($path.'/'.uniqid(mt_rand()).'.tmp');
// check tmp file for read/write capabilities
$rm = file_exists($path);
$f = @fopen($path, 'a');
if ($f===false)
return false;
fclose($f);
if (!$rm)
unlink($path);
return true;
}
?>
----
Server IP: 213.92.11.19
Probable Submitter: 151.44.87.253
----
Manual Page -- http://www.php.net/manual/en/function.is-writable.php
Edit -- https://master.php.net/note/edit/73596
Del: integrated -- https://master.php.net/note/delete/73596/integrated
Del: useless -- https://master.php.net/note/delete/73596/useless
Del: bad code -- https://master.php.net/note/delete/73596/bad+code
Del: spam -- https://master.php.net/note/delete/73596/spam
Del: non-english -- https://master.php.net/note/delete/73596/non-english
Del: in docs -- https://master.php.net/note/delete/73596/in+docs
Del: other reasons-- https://master.php.net/note/delete/73596
Reject -- https://master.php.net/note/reject/73596
Search -- https://master.php.net/manage/user-notes.php