예제 #1
0
 /**
  * performs an initial move of an uploaded file
  * from its temporary folder to a destination folder
  * and renames it to the original filename
  * once completed a flag is set and subsequent
  * moves are redirected to the parent method
  * 
  * (non-PHPdoc)
  * @see \vxPHP\File\FilesystemFile::move()
  */
 public function move(FilesystemFolder $destination)
 {
     if ($this->alreadyUploaded) {
         return parent::move($destination);
     }
     $oldpath = $this->folder->getPath() . $this->filename;
     $filename = self::sanitizeFilename($this->originalName, $destination);
     $newpath = $destination->getPath() . $filename;
     // ensure that only uploaded files are handled
     if (is_uploaded_file($oldpath)) {
         // move uploaded file
         if (@move_uploaded_file($oldpath, $newpath)) {
             // flag completed upload
             $this->alreadyUploaded = TRUE;
             // set new folder reference
             $this->folder = $destination;
             // set new filename
             $this->filename = $filename;
             // re-read fileinfo
             $this->fileInfo = new \SplFileInfo($newpath);
             // set cached instance
             self::$instances[$newpath] = $this;
             // @todo: check necessity of chmod
             @chmod($newpath, 0666 & ~umask());
         } else {
             throw new FilesystemFileException("Could not move uploaded file '" . $this->originalName . "' to '" . $newpath . "'.", FilesystemFileException::FILE_RENAME_FAILED);
         }
     } else {
         throw new FilesystemFileException("File '" . $oldpath . "' was not identified as uploaded file.");
     }
     return $this;
 }
예제 #2
0
파일: MetaFile.php 프로젝트: vectrex/vxphp
 /**
  * move file to a new folder
  *
  * @param MetaFolder $destination
  * @throws MetaFileException
  */
 public function move(MetaFolder $destination)
 {
     // nothing to do
     if ($destination === $this->metaFolder) {
         return;
     }
     // move filesystem file first
     try {
         $this->filesystemFile->move($destination->getFilesystemFolder());
     } catch (FilesystemFileException $e) {
         throw new MetaFileException("Moving '{$this->getFilename()}' to '{$destination->getFullPath()}' failed.");
     }
     // update reference in db
     try {
         Application::getInstance()->getDb()->execute('UPDATE files SET foldersID = ? WHERE filesID = ?', array($destination->getId(), $this->id));
     } catch (\Exception $e) {
         throw new MetaFileException("Moving '{$this->getFilename()}' to '{$destination->getFullPath()}' failed.");
     }
     // update instance lookup
     unset(self::$instancesByPath[$this->getPath()]);
     $this->metaFolder = $destination;
     self::$instancesByPath[$this->getPath()] = $this;
 }