Before we jump in, we must import the
relevant library in order to use the JPath class:
jimport('joomla.filesystem.path');
We'll start by looking at the clean() method. This method is used to tidy up a
path by removing any unnecessary directory separators and ensuring all remaining
directory separators are of the correct type for the current system.
This example demonstrates how we use the clean() method:
$path = JPATH_BASE.'\foo//bar\\baz';
$cleanPath = JPath::clean($path);
The values displayed demonstrate the values associated with $path and $cleanPath
respectively (assuming JPATH_BASE is equal to /var/www/html/joomla):
$path: /var/www/html/joomla\foo//bar\\baz
ScleanPath: /var/www/html/joomla/foo/bar/baz
A similar method in the JPath class is the check() method. This method is used to
prevent snooping. For more information about this method refer to Chapter 11.
The next method we will look at is the find() method. We use this method to search
for a specific file that might be located in a number of different paths.
Pages:
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479