summaryrefslogtreecommitdiffstats
path: root/system/helpers/file_helper.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/helpers/file_helper.php')
-rw-r--r--system/helpers/file_helper.php53
1 files changed, 26 insertions, 27 deletions
diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php
index 7270ee32c..aebb6e47a 100644
--- a/system/helpers/file_helper.php
+++ b/system/helpers/file_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter File Helpers
@@ -32,7 +33,7 @@
* @subpackage Helpers
* @category Helpers
* @author EllisLab Dev Team
- * @link http://codeigniter.com/user_guide/helpers/file_helpers.html
+ * @link http://codeigniter.com/user_guide/helpers/file_helper.html
*/
// ------------------------------------------------------------------------
@@ -44,12 +45,10 @@ if ( ! function_exists('read_file'))
*
* Opens the file specfied in the path and returns it as a string.
*
- * This function is DEPRECATED and should be removed in
- * CodeIgniter 3.1+. Use file_get_contents() instead.
- *
- * @deprecated
- * @param string path to file
- * @return string
+ * @todo Remove in version 3.1+.
+ * @deprecated 3.0.0 It is now just an alias for PHP's native file_get_contents().
+ * @param string $file Path to file
+ * @return string File contents
*/
function read_file($file)
{
@@ -67,12 +66,12 @@ if ( ! function_exists('write_file'))
* Writes data to the file specified in the path.
* Creates a new file if non-existent.
*
- * @param string path to file
- * @param string file data
- * @param int
+ * @param string $path File path
+ * @param string $data Data to write
+ * @param string $mode fopen() mode (default: 'wb')
* @return bool
*/
- function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE)
+ function write_file($path, $data, $mode = 'wb')
{
if ( ! $fp = @fopen($path, $mode))
{
@@ -100,16 +99,16 @@ if ( ! function_exists('delete_files'))
* If the second parameter is set to TRUE, any directories contained
* within the supplied base directory will be nuked as well.
*
- * @param string path to file
- * @param bool whether to delete any directories found in the path
- * @param int
- * @param bool whether to skip deleting .htaccess and index page files
+ * @param string $path File path
+ * @param bool $del_dir Whether to delete any directories found in the path
+ * @param bool $htdocs Whether to skip deleting .htaccess and index page files
+ * @param int $_level Current directory depth level (default: 0; internal use only)
* @return bool
*/
- function delete_files($path, $del_dir = FALSE, $level = 0, $htdocs = FALSE)
+ function delete_files($path, $del_dir = FALSE, $htdocs = FALSE, $_level = 0)
{
// Trim the trailing slash
- $path = rtrim($path, DIRECTORY_SEPARATOR);
+ $path = rtrim($path, '/\\');
if ( ! $current_dir = @opendir($path))
{
@@ -122,9 +121,9 @@ if ( ! function_exists('delete_files'))
{
if (is_dir($path.DIRECTORY_SEPARATOR.$filename) && $filename[0] !== '.')
{
- delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $level + 1, $htdocs);
+ delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $htdocs, $_level + 1);
}
- elseif ($htdocs === TRUE && ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename))
+ elseif ($htdocs !== TRUE OR ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename))
{
@unlink($path.DIRECTORY_SEPARATOR.$filename);
}
@@ -132,7 +131,7 @@ if ( ! function_exists('delete_files'))
}
@closedir($current_dir);
- if ($del_dir === TRUE && $level > 0)
+ if ($del_dir === TRUE && $_level > 0)
{
return @rmdir($path);
}
@@ -320,12 +319,12 @@ if ( ! function_exists('get_mime_by_extension'))
* Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience
* It should NOT be trusted, and should certainly NOT be used for security
*
- * @param string path to file
- * @return mixed
+ * @param string $filename File name
+ * @return string
*/
- function get_mime_by_extension($file)
+ function get_mime_by_extension($filename)
{
- $extension = strtolower(substr(strrchr($file, '.'), 1));
+ $extension = strtolower(substr(strrchr($filename, '.'), 1));
static $mimes;
@@ -360,7 +359,7 @@ if ( ! function_exists('symbolic_permissions'))
* Takes a numeric value representing a file's permissions and returns
* standard symbolic notation representing that value
*
- * @param int
+ * @param int $perms Permissions
* @return string
*/
function symbolic_permissions($perms)
@@ -427,7 +426,7 @@ if ( ! function_exists('octal_permissions'))
* Takes a numeric value representing a file's permissions and returns
* a three character string representing the file's octal permissions
*
- * @param int
+ * @param int $perms Permissions
* @return string
*/
function octal_permissions($perms)