Example #1
0
 public function move(\Coast\File $file)
 {
     if (!$file->exists()) {
         throw new \Exception("File '{$file}' does not exist");
     }
     $this->remove();
     $this->name(ucwords(trim(preg_replace('/[_]+/', ' ', $file->fileName()))));
     $this->size = $file->size();
     $this->hash = $file->hash('md5');
     $extName = strtolower($file->extName());
     if ($extName) {
         foreach (self::$_mimeTypes as $mimeType => $info) {
             if (in_array($extName, $info[1])) {
                 $this->subtype = $mimeType;
                 break;
             }
         }
     }
     if (!isset($this->subtype)) {
         $this->subtype = 'application/octet-stream';
     }
     $regex = '/[\\/\\?<>\\:\\*\\|":\\x00-\\x1f\\x80-\\x9f]/';
     $sanitized = clone $file;
     $sanitized->baseName(preg_replace($regex, '', $file->baseName()));
     $i = 0;
     $dir = $this->dir();
     do {
         $temp = clone $sanitized;
         if ($i > 0) {
             $temp->suffix("-{$i}");
         }
         $i++;
     } while ($dir->file($temp->baseName())->exists());
     $this->baseName($temp->baseName());
     $this->file = $file->move($dir, $this->baseName);
     return $this;
 }
Example #2
0
function is_image(\Coast\File $file)
{
    $exts = ['gif', 'jpg', 'jpeg', 'png', 'webp'];
    return in_array($file->extName(), $exts);
}
Example #3
0
 protected function _generateOutput(File $file, $transforms, array $params)
 {
     sort($transforms);
     ksort($params);
     $id = md5($file->name() . $file->modifyTime()->getTimestamp() . serialize($transforms) . serialize($params));
     return $this->_outputDir->dir("{$id[0]}/{$id[1]}", true)->file("{$id}.{$file->extName()}");
 }