| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * CodeIgniter | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  |  * An open source application development framework for PHP | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  |  * This content is released under the MIT License (MIT) | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-11-07 03:05:55 +08:00
										 |  |  |  * Copyright (c) 2014 - 2019, British Columbia Institute of Technology | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Permission is hereby granted, free of charge, to any person obtaining a copy | 
					
						
							|  |  |  |  * of this software and associated documentation files (the "Software"), to deal | 
					
						
							|  |  |  |  * in the Software without restriction, including without limitation the rights | 
					
						
							|  |  |  |  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
					
						
							|  |  |  |  * copies of the Software, and to permit persons to whom the Software is | 
					
						
							|  |  |  |  * furnished to do so, subject to the following conditions: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The above copyright notice and this permission notice shall be included in | 
					
						
							|  |  |  |  * all copies or substantial portions of the Software. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
					
						
							|  |  |  |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
					
						
							|  |  |  |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
					
						
							|  |  |  |  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
					
						
							|  |  |  |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
					
						
							|  |  |  |  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
					
						
							|  |  |  |  * THE SOFTWARE. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @package	CodeIgniter | 
					
						
							|  |  |  |  * @author	EllisLab Dev Team | 
					
						
							|  |  |  |  * @copyright	Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) | 
					
						
							| 
									
										
										
										
											2021-11-07 03:05:55 +08:00
										 |  |  |  * @copyright	Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/) | 
					
						
							|  |  |  |  * @license	https://opensource.org/licenses/MIT	MIT License | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  |  * @link	https://codeigniter.com | 
					
						
							|  |  |  |  * @since	Version 1.0.0 | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  |  * @filesource | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | defined('BASEPATH') OR exit('No direct script access allowed'); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * CodeIgniter File Helpers | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @package		CodeIgniter | 
					
						
							|  |  |  |  * @subpackage	Helpers | 
					
						
							|  |  |  |  * @category	Helpers | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  |  * @author		EllisLab Dev Team | 
					
						
							| 
									
										
										
										
											2021-11-07 03:05:55 +08:00
										 |  |  |  * @link		https://codeigniter.com/userguide3/helpers/file_helper.html | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // ------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if ( ! function_exists('write_file')) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Write File | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * Writes data to the file specified in the path. | 
					
						
							|  |  |  | 	 * Creates a new file if non-existent. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @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 = 'wb') | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		if ( ! $fp = @fopen($path, $mode)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return FALSE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		flock($fp, LOCK_EX); | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		for ($result = $written = 0, $length = strlen($data); $written < $length; $written += $result) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			if (($result = fwrite($fp, substr($data, $written))) === FALSE) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		flock($fp, LOCK_UN); | 
					
						
							|  |  |  | 		fclose($fp); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		return is_int($result); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // ------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if ( ! function_exists('delete_files')) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Delete Files | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * Deletes all files contained in the supplied directory path. | 
					
						
							|  |  |  | 	 * Files must be writable or owned by the system in order to be deleted. | 
					
						
							|  |  |  | 	 * If the second parameter is set to TRUE, any directories contained | 
					
						
							|  |  |  | 	 * within the supplied base directory will be nuked as well. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @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, $htdocs = FALSE, $_level = 0) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		// Trim the trailing slash
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		$path = rtrim($path, '/\\'); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if ( ! $current_dir = @opendir($path)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return FALSE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		while (FALSE !== ($filename = @readdir($current_dir))) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 			if ($filename !== '.' && $filename !== '..') | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 				$filepath = $path.DIRECTORY_SEPARATOR.$filename; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (is_dir($filepath) && $filename[0] !== '.' && ! is_link($filepath)) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 					delete_files($filepath, $del_dir, $htdocs, $_level + 1); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 				elseif ($htdocs !== TRUE OR ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename)) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 					@unlink($filepath); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		closedir($current_dir); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		return ($del_dir === TRUE && $_level > 0) | 
					
						
							|  |  |  | 			? @rmdir($path) | 
					
						
							|  |  |  | 			: TRUE; | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // ------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if ( ! function_exists('get_filenames')) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Get Filenames | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * Reads the specified directory and builds an array containing the filenames. | 
					
						
							|  |  |  | 	 * Any sub-folders contained within the specified path are read as well. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param	string	path to source | 
					
						
							|  |  |  | 	 * @param	bool	whether to include the path as part of the filename | 
					
						
							|  |  |  | 	 * @param	bool	internal variable to determine recursion status - do not use in calls | 
					
						
							|  |  |  | 	 * @return	array | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		static $_filedata = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ($fp = @opendir($source_dir)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			// reset the array and make sure $source_dir has a trailing slash on the initial call
 | 
					
						
							|  |  |  | 			if ($_recursion === FALSE) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				$_filedata = array(); | 
					
						
							|  |  |  | 				$source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			while (FALSE !== ($file = readdir($fp))) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 				if (is_dir($source_dir.$file) && $file[0] !== '.') | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 				{ | 
					
						
							|  |  |  | 					get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 				elseif ($file[0] !== '.') | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 					$_filedata[] = ($include_path === TRUE) ? $source_dir.$file : $file; | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			closedir($fp); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 			return $_filedata; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return FALSE; | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if ( ! function_exists('get_dir_file_info')) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Get Directory File Information | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * Reads the specified directory and builds an array containing the filenames, | 
					
						
							|  |  |  | 	 * filesize, dates, and permissions | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * Any sub-folders contained within the specified path are read as well. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param	string	path to source | 
					
						
							|  |  |  | 	 * @param	bool	Look only at the top level directory specified? | 
					
						
							|  |  |  | 	 * @param	bool	internal variable to determine recursion status - do not use in calls | 
					
						
							|  |  |  | 	 * @return	array | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	function get_dir_file_info($source_dir, $top_level_only = TRUE, $_recursion = FALSE) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		static $_filedata = array(); | 
					
						
							|  |  |  | 		$relative_path = $source_dir; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ($fp = @opendir($source_dir)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			// reset the array and make sure $source_dir has a trailing slash on the initial call
 | 
					
						
							|  |  |  | 			if ($_recursion === FALSE) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				$_filedata = array(); | 
					
						
							|  |  |  | 				$source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 			// Used to be foreach (scandir($source_dir, 1) as $file), but scandir() is simply not as fast
 | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 			while (FALSE !== ($file = readdir($fp))) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 				if (is_dir($source_dir.$file) && $file[0] !== '.' && $top_level_only === FALSE) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 				{ | 
					
						
							|  |  |  | 					get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, TRUE); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 				elseif ($file[0] !== '.') | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 				{ | 
					
						
							|  |  |  | 					$_filedata[$file] = get_file_info($source_dir.$file); | 
					
						
							|  |  |  | 					$_filedata[$file]['relative_path'] = $relative_path; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 			closedir($fp); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 			return $_filedata; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return FALSE; | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if ( ! function_exists('get_file_info')) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Get File Info | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * Given a file and path, returns the name, path, size, date modified | 
					
						
							|  |  |  | 	 * Second parameter allows you to explicitly declare what information you want returned | 
					
						
							|  |  |  | 	 * Options are: name, server_path, size, date, readable, writable, executable, fileperms | 
					
						
							|  |  |  | 	 * Returns FALSE if the file cannot be found. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param	string	path to file | 
					
						
							|  |  |  | 	 * @param	mixed	array or comma separated string of information returned | 
					
						
							|  |  |  | 	 * @return	array | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	function get_file_info($file, $returned_values = array('name', 'server_path', 'size', 'date')) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if ( ! file_exists($file)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return FALSE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (is_string($returned_values)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			$returned_values = explode(',', $returned_values); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		foreach ($returned_values as $key) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			switch ($key) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				case 'name': | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 					$fileinfo['name'] = basename($file); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				case 'server_path': | 
					
						
							|  |  |  | 					$fileinfo['server_path'] = $file; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				case 'size': | 
					
						
							|  |  |  | 					$fileinfo['size'] = filesize($file); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				case 'date': | 
					
						
							|  |  |  | 					$fileinfo['date'] = filemtime($file); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				case 'readable': | 
					
						
							|  |  |  | 					$fileinfo['readable'] = is_readable($file); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				case 'writable': | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 					$fileinfo['writable'] = is_really_writable($file); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				case 'executable': | 
					
						
							|  |  |  | 					$fileinfo['executable'] = is_executable($file); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				case 'fileperms': | 
					
						
							|  |  |  | 					$fileinfo['fileperms'] = fileperms($file); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return $fileinfo; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if ( ! function_exists('get_mime_by_extension')) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Get Mime by Extension | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * Translates a file extension into a mime type based on config/mimes.php. | 
					
						
							|  |  |  | 	 * Returns FALSE if it can't determine the type, or open the mime config file | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * 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	$filename	File name | 
					
						
							|  |  |  | 	 * @return	string | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	function get_mime_by_extension($filename) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		static $mimes; | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if ( ! is_array($mimes)) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 			$mimes = get_mimes(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (empty($mimes)) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 			{ | 
					
						
							|  |  |  | 				return FALSE; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		$extension = strtolower(substr(strrchr($filename, '.'), 1)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (isset($mimes[$extension])) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 			return is_array($mimes[$extension]) | 
					
						
							|  |  |  | 				? current($mimes[$extension]) // Multiple mime types, just give the first one
 | 
					
						
							|  |  |  | 				: $mimes[$extension]; | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return FALSE; | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if ( ! function_exists('symbolic_permissions')) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Symbolic Permissions | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * Takes a numeric value representing a file's permissions and returns | 
					
						
							|  |  |  | 	 * standard symbolic notation representing that value | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param	int	$perms	Permissions | 
					
						
							|  |  |  | 	 * @return	string | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	function symbolic_permissions($perms) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		if (($perms & 0xC000) === 0xC000) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			$symbolic = 's'; // Socket
 | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		elseif (($perms & 0xA000) === 0xA000) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			$symbolic = 'l'; // Symbolic Link
 | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		elseif (($perms & 0x8000) === 0x8000) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			$symbolic = '-'; // Regular
 | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		elseif (($perms & 0x6000) === 0x6000) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			$symbolic = 'b'; // Block special
 | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		elseif (($perms & 0x4000) === 0x4000) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			$symbolic = 'd'; // Directory
 | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		elseif (($perms & 0x2000) === 0x2000) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			$symbolic = 'c'; // Character special
 | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		elseif (($perms & 0x1000) === 0x1000) | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			$symbolic = 'p'; // FIFO pipe
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			$symbolic = 'u'; // Unknown
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Owner
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		$symbolic .= (($perms & 0x0100) ? 'r' : '-') | 
					
						
							|  |  |  | 			.(($perms & 0x0080) ? 'w' : '-') | 
					
						
							|  |  |  | 			.(($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-')); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Group
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		$symbolic .= (($perms & 0x0020) ? 'r' : '-') | 
					
						
							|  |  |  | 			.(($perms & 0x0010) ? 'w' : '-') | 
					
						
							|  |  |  | 			.(($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-')); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// World
 | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 		$symbolic .= (($perms & 0x0004) ? 'r' : '-') | 
					
						
							|  |  |  | 			.(($perms & 0x0002) ? 'w' : '-') | 
					
						
							|  |  |  | 			.(($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-')); | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return $symbolic; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // --------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if ( ! function_exists('octal_permissions')) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-07 08:45:06 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * 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	$perms	Permissions | 
					
						
							|  |  |  | 	 * @return	string | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | 	function octal_permissions($perms) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return substr(sprintf('%o', $perms), -3); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |