Actions

API16

JPath/find

From Joomla! Documentation

< API16:JPath
Revision as of 17:47, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Searches the directory paths for a given file.

[Edit Descripton]

Description:JPath/find

Syntax

static find($paths, $file)
Parameter Name Default Value Description
$paths $path An path or array of path to search in
$file $file The file name to look for.

Returns

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.

Defined in

libraries/joomla/filesystem/path.php

Importing

jimport( 'joomla.filesystem.path' );

Source Body

public static function find($paths, $file)
{
        settype($paths, 'array'); //force to array
 
        // 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
                        $fullname = realpath($fullname);
                }
 
                // 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
                // traversal attempts.
                if (file_exists($fullname) && substr($fullname, 0, strlen($path)) == $path) {
                        return $fullname;
                }
        }
 
        // could not find the file in the set of paths
        return false;
}

[Edit See Also] SeeAlso:JPath/find

Examples

<CodeExamplesForm />