コード例 #1
0
ファイル: UploadedFile.php プロジェクト: vectrex/vxphp
 /**
  * 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
 /**
  * commit changes to metadata by writing data to database
  */
 private function commit()
 {
     try {
         Application::getInstance()->getDb()->updateRecord('files', $this->id, $this->data);
     } catch (\PDOException $e) {
         throw new MetaFileException("Data commit of file '" . $this->filesystemFile->getFilename() . "' failed. PDO reports " . $e->getMessage());
     }
 }
コード例 #3
0
ファイル: FilesystemFolder.php プロジェクト: vectrex/vxphp
 /**
  * empties folder
  * removes all files in folder and subfolders (including any cache folders)
  *
  * @throws FilesystemFolderException
  */
 public function purge()
 {
     foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->path, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST) as $f) {
         if ($f->isDir()) {
             if (!@rmdir($f->getRealPath())) {
                 throw new FilesystemFolderException(sprintf('Filesystem folder %s could not be deleted!', $f->getRealPath()));
             }
             self::unsetInstance($f->getRealPath());
         } else {
             if (!@unlink($f->getRealPath())) {
                 throw new FilesystemFolderException(sprintf('Filesystem file %s could not be deleted!', $f->getRealPath()));
             }
             FilesystemFile::unsetInstance($f->getRealPath());
         }
     }
 }