summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDerek Allard <derek.allard@ellislab.com>2008-01-09 15:18:14 +0100
committerDerek Allard <derek.allard@ellislab.com>2008-01-09 15:18:14 +0100
commite4e603b1083242fd08fc84e2cb29e998dddaee0c (patch)
treec937708c7fd687d771facc8ab25c2e93311e789e
parentfd5c01a1c14f396bb63b3e2dce7dab2548a1cefa (diff)
fix for is_really_writable
-rw-r--r--system/helpers/file_helper.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php
index d07d35f97..83ef6a066 100644
--- a/system/helpers/file_helper.php
+++ b/system/helpers/file_helper.php
@@ -176,4 +176,39 @@ function get_filenames($source_dir, $include_path = FALSE)
}
}
+// --------------------------------------------------------------------
+
+/**
+ * Tests for file writability
+ *
+ * is_writable() returns TRUE on Windows servers
+ * when you really can't write to the file
+ * as the OS reports to PHP as FALSE only if the
+ * read-only attribute is marked. Ugh?
+ *
+ * @access private
+ * @return void
+ */
+function is_really_writable($file)
+{
+ if (is_dir($file))
+ {
+ $file = rtrim($file, '/').'/'.md5(rand(1,100));
+
+ if (($fp = @fopen($file, 'ab')) === FALSE)
+ {
+ return FALSE;
+ }
+
+ @chmod($file, 0777);
+ @unlink($file);
+ }
+ elseif (($fp = @fopen($file, 'ab')) === FALSE)
+ {
+ return FALSE;
+ }
+
+ fclose($fp);
+ return TRUE;
+}
?> \ No newline at end of file