Files::fixPath PHP Method

fixPath() public method

Append a / to the path if required.
public fixPath ( string $path ) : string
$path string the path
return string path with trailing /
    function fixPath($path)
    {
        //append a slash to the path if it doesn't exists.
        if (!(substr($path, -1) == '/')) {
            $path .= '/';
        }
        return $path;
    }

Usage Example

 /**
  * Get all the files and directories of a relative path.
  * @param string $path relative path to be base path.
  * @return array of file and path information.
  * <code>array(0=>array('relative'=>'fullpath',...), 1=>array('filename'=>fileinfo array(),...)</code>
  * fileinfo array: <code>array('url'=>'full url', 
  *                       'relative'=>'relative to base', 
  *                        'fullpath'=>'full file path', 
  *                        'image'=>imageInfo array() false if not image,
  *                        'stat' => filestat)</code>
  */
 function getFiles($path)
 {
     $files = array();
     $dirs = array();
     if ($this->isValidBase() == false) {
         return array($files, $dirs);
     }
     $path = Files::fixPath($path);
     $base = Files::fixPath($this->getImagesDir());
     $fullpath = Files::makePath($base, $path);
     $d = @dir($fullpath);
     while (false !== ($entry = $d->read())) {
         //not a dot file or directory
         if (substr($entry, 0, 1) != '.') {
             if (is_dir($fullpath . $entry) && $this->isThumbDir($entry) == false) {
                 $relative = Files::fixPath($path . $entry);
                 $full = Files::fixPath($fullpath . $entry);
                 $count = $this->countFiles($full);
                 $dirs[$relative] = array('fullpath' => $full, 'entry' => $entry, 'count' => $count);
             } else {
                 if (is_file($fullpath . $entry) && $this->isThumb($entry) == false && $this->isTmpFile($entry) == false) {
                     $img = $this->getImageInfo($fullpath . $entry);
                     if (!(!is_array($img) && $this->config['validate_images'])) {
                         $file['url'] = Files::makePath($this->config['base_url'], $path) . $entry;
                         $file['relative'] = $path . $entry;
                         $file['fullpath'] = $fullpath . $entry;
                         $file['image'] = $img;
                         $file['stat'] = stat($fullpath . $entry);
                         $files[$entry] = $file;
                     }
                 }
             }
         }
     }
     $d->close();
     ksort($dirs);
     ksort($files);
     return array($dirs, $files);
 }
All Usage Examples Of Files::fixPath