public function add($file, $force = false)
    {
        if (!file_exists($file)) {
            throw new \InvalidArgumentException(sprintf('File "%s" does not exist.', $file));
        }

        if (false === $force && null !== $path = $this->getCache($file)) {
            return null === $this->target ? $path : $this->target.'/'.$path;
        }

        $name = $this->findAvailableName($file);

        if (null !== $this->cache) {
            $this->cache->set(md5($file), serialize(array(filemtime($file), $name)));
        }

        if (!is_dir($dir = dirname($target = $this->directory.'/'.$name))) {
            mkdir($dir, 0777, true);
        }

        if (false === @copy($file, $target)) {
            throw new \RuntimeException(sprintf('Error while copying "%s" to "%s".', $file, $target));
        }

        return null === $this->target ? $name : $this->target.'/'.$name;
    }
public function add($file, $force = false)
    {
        if (!file_exists($file)) {
            throw new \InvalidArgumentException(sprintf('File "%s" does not exist.', $file));
        }

        if (false === $force && null !== $path = $this->getCache($file)) {
            return null === $this->target ? $path : $this->target.'/'.$path;
        }

        $name = $this->findAvailableName($file);

        if (null !== $this->cache) {
            $this->cache->set(md5($file), serialize(array(filemtime($file), $name)));
        }

        if (!is_dir($dir = dirname($target = $this->directory.'/'.$name))) {
            mkdir($dir, 0777, true);
        }

        if (false === @copy($file, $target)) {
            throw new \RuntimeException(sprintf('Error while copying "%s" to "%s".', $file, $target));
        }

        return null === $this->target ? $name : $this->target.'/'.$name;
    }
public function add ( $ file , $ force = false ) { if ( ! file_exists ( $ file ) ) { throw new \ InvalidArgumentException ( sprintf ( 'File "%s" does not exist.' , $ file ) ) ; } if ( false === $ force && null !== $ path = $ this -> getCache ( $ file ) ) { return null === $ this -> target ? $ path : $ this -> target . '/' . $ path ; } $ name = $ this -> findAvailableName ( $ file ) ; if ( null !== $ this -> cache ) { $ this -> cache -> set ( md5 ( $ file ) , serialize ( array ( filemtime ( $ file ) , $ name ) ) ) ; } if ( ! is_dir ( $ dir = dirname ( $ target = $ this -> directory . '/' . $ name ) ) ) { mkdir ( $ dir , 0777 , true ) ; } if ( false === @ copy ( $ file , $ target ) ) { throw new \ RuntimeException ( sprintf ( 'Error while copying "%s" to "%s".' , $ file , $ target ) ) ; } return null === $ this -> target ? $ name : $ this -> target . '/' . $ name ; }
Copy a file to the directory.

@param string  $file  fullpath of file to add
@param boolean $force ignore cache and add file to directory

@throws InvalidArgumentException file does not exist
@throws RuntimeException filesystem errors

@return string target image path
Copy a file to the directory .