Ejemplo n.º 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;
 }