Source code for file /joomla/filesystem/path.php
Documentation is available at path.php
* @version $Id: path.php 6559 2007-02-10 18:22:43Z friesengeist $
* @package Joomla.Framework
* @copyright Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
/** boolean True if a Windows based host */
define('JPATH_ISWIN', (strtoupper(substr(PHP_OS, 0, 3)) ===
'WIN'));
/** boolean True if a Mac based host */
define('JPATH_ISMAC', (strtoupper(substr(PHP_OS, 0, 3)) ===
'MAC'));
/** string Shortcut for the DIRECTORY_SEPARATOR define */
define('DS', DIRECTORY_SEPARATOR);
/** string The root directory of the file system in native format */
define('JPATH_ROOT', JPath::clean(JPATH_SITE));
* @package Joomla.Framework
* Checks if a path's permissions can be changed
* @param string $path Path to check
* @return boolean True if path can have mode changed
if (@ chmod($path, $perms ^
0001))
* Chmods files and directories recursivly to given permissions
* @param string $path Root path to begin changing mode [without trailing slash]
* @param string $filemode Octal representation of the value to change file mode to [null = no change]
* @param string $foldermode Octal representation of the value to change folder mode to [null = no change]
* @return boolean True if successful [one fail means the whole operation failed]
function setPermissions($path, $filemode =
'0644', $foldermode =
'0755') {
// Initialize return value
if ($file !=
'.' &&
$file !=
'..') {
$fullpath =
$path.
'/'.
$file;
if (isset
($foldermode)) {
* Get the permissions of the file/folder at a give path
* @param string $path The path of a file/folder
* @return string Filesystem permissions
for ($i =
0; $i <
3; $i ++
)
$parsed_mode .=
($mode { $i } & 04) ?
"r" :
"-";
$parsed_mode .=
($mode { $i } & 02) ?
"w" :
"-";
$parsed_mode .=
($mode { $i } & 01) ?
"x" :
"-";
* Checks for snooping outside of the file system root
* @param string $path A file system path to check
* @return string A cleaned version of the path
if (strpos($path, '..') !==
false) {
JError::raiseError( 20, 'JPath::check Use of relative paths not permitted'); // don't translate
JError::raiseError( 20, 'JPath::check Snooping out of bounds @ '.
$path); // don't translate
* Function to strip additional / or \ in a path name
* @param string $path The path to clean
* @param string $ds Directory separator (optional)
* @return string The cleaned path
function clean($path, $ds=
DS)
// Remove double slashes and backslahses and convert all slashes and backslashes to DS
* Method to determine if script owns the path
* @param string $path Path to check ownership
* @return boolean True if the php script owns the path passed
* Searches the directory paths for a given file.
* @param array $path An array of paths to search in
* @param string $file The file name to look for.
* @return mixed The full path and file name for the target file, or boolean false if the file is not found in any of the paths.
function find($paths, $file)
// start looping through the path set
foreach ($paths as $path)
// get the path to the file
$fullname =
$path.
DS.
$file;
// is the path based on a stream?
if (strpos($path, '://') ===
false)
// not a stream, so do a realpath() to avoid directory
// traversal attempts on the local file system.
$path =
realpath($path); // needed for substr() later
// the substr() check added to make sure that the realpath()
// results in a directory registered so that
// non-registered directores are not accessible via directory
// could not find the file in the set of paths