Nette\Http\FileUpload::move PHP Метод

move() публичный Метод

Move uploaded file to new location.
public move ( $dest ) : self
Результат self
    public function move($dest)
    {
        $dir = dirname($dest);
        @mkdir($dir, 0777, TRUE);
        // @ - dir may already exist
        if (!is_dir($dir)) {
            throw new Nette\InvalidStateException("Directory '{$dir}' cannot be created. " . error_get_last()['message']);
        }
        @unlink($dest);
        // @ - file may not exists
        Nette\Utils\Callback::invokeSafe(is_uploaded_file($this->tmpName) ? 'move_uploaded_file' : 'rename', [$this->tmpName, $dest], function ($message) use($dest) {
            throw new Nette\InvalidStateException("Unable to move uploaded file '{$this->tmpName}' to '{$dest}'. {$message}");
        });
        @chmod($dest, 0666);
        // @ - possible low permission to chmod
        $this->tmpName = $dest;
        return $this;
    }

Usage Example

Пример #1
1
 /**
  * @ORM\PreFlush()
  */
 public function preUpload()
 {
     if ($this->file) {
         if ($this->file instanceof FileUpload) {
             $basename = $this->file->getSanitizedName();
             $basename = $this->suggestName($this->getFilePath(), $basename);
             $this->setName($basename);
         } else {
             $basename = trim(Strings::webalize($this->file->getBasename(), '.', FALSE), '.-');
             $basename = $this->suggestName(dirname($this->file->getPathname()), $basename);
             $this->setName($basename);
         }
         if ($this->_oldPath && $this->_oldPath !== $this->path) {
             @unlink($this->getFilePathBy($this->_oldProtected, $this->_oldPath));
         }
         if ($this->file instanceof FileUpload) {
             $this->file->move($this->getFilePath());
         } else {
             copy($this->file->getPathname(), $this->getFilePath());
         }
         return $this->file = NULL;
     }
     if (($this->_oldPath || $this->_oldProtected !== NULL) && ($this->_oldPath != $this->path || $this->_oldProtected != $this->protected)) {
         $oldFilePath = $this->getFilePathBy($this->_oldProtected !== NULL ? $this->_oldProtected : $this->protected, $this->_oldPath ?: $this->path);
         if (file_exists($oldFilePath)) {
             rename($oldFilePath, $this->getFilePath());
         }
     }
 }
All Usage Examples Of Nette\Http\FileUpload::move