You are here

class FileUploaded in N1ED - Visual editor as CKEditor plugin with Bootstrap support 7

Hierarchy

  • class \EdSDK\FileUploaderServer\lib\file\AFile

Expanded class hierarchy of FileUploaded

3 files declare their use of FileUploaded
ActionUploadAddFile.php in vendor/edsdk/file-uploader-server-php/src/lib/action/ActionUploadAddFile.php
ActionUploadCommit.php in vendor/edsdk/file-uploader-server-php/src/lib/action/ActionUploadCommit.php
ActionUploadRemoveFile.php in vendor/edsdk/file-uploader-server-php/src/lib/action/ActionUploadRemoveFile.php

File

vendor/edsdk/file-uploader-server-php/src/lib/file/FileUploaded.php, line 15

Namespace

EdSDK\FileUploaderServer\lib\file
View source
class FileUploaded extends AFile {
  protected $m_newName;
  protected $m_confilictsErrors = [];
  protected $m_customErrors = [];
  public function __construct($config, $dir, $name, $newName) {
    parent::__construct($config, $dir, $name);
    $this->m_newName = $newName;
  }
  public function getBaseDir() {
    return $this->m_config
      ->getTmpDir();
  }
  public function getNewName() {
    return $this->m_newName;
  }
  public function checkForErrors($checkForExist) {
    if (!parent::checkForErrors($checkForExist)) {
      return false;
    }
    if ($this->m_newName !== $this
      ->getName() && !Utils::isFileNameSyntaxOk($this->m_newName)) {
      $this->m_commonErrors[] = Message::createMessage(Message::FILE_ERROR_SYNTAX, $this->m_newName);
    }
    if (Utils::isImage($this
      ->getName())) {
      $ext = $this
        ->getExt();
      $newExt = Utils::getExt($this->m_newName);
      if ($ext !== $newExt) {
        if (!($ext === "jpg" && $newExt === "jpeg") && !($ext === "jpeg" && $newExt === "jpg")) {
          $this->m_commonErrors[] = Message::createMessage(Message::FILE_ERROR_INCORRECT_IMAGE_EXT_CHANGE, $ext, $newExt);
        }
      }
    }
    return true;
  }
  public function addCustomError($message) {
    $this->m_customErrors[] = $message;
  }
  public function getErrors() {
    $errors = (array) parent::getErrors();
    for ($i = 0; $i < count($this->m_confilictsErrors); $i++) {
      $errors[] = $this->m_confilictsErrors[$i];
    }
    for ($i = 0; $i < count($this->m_customErrors); $i++) {
      $errors[] = $this->m_customErrors[$i];
    }
    return $errors;
  }
  public function getCommitedFile($dir) {
    return new FileCommited($this->m_config, $dir, $this->m_newName);
  }
  public function checkForConflicts($dir) {
    $this->m_confilictsErrors = [];
    $file = $this
      ->getCommitedFile($dir);
    if ($file
      ->exists()) {
      $this->m_confilictsErrors[] = Message::createMessage(Message::FILE_ALREADY_EXISTS, $file
        ->getName());
    }
    if ($file
      ->isImage()) {
      $fileOriginal = $file
        ->getFileOriginal();
      if ($fileOriginal
        ->exists()) {
        $this->m_confilictsErrors[] = Message::createMessage(Message::FILE_ALREADY_EXISTS, $fileOriginal
          ->getName());
      }
      $filePreview = $file
        ->getFilePreview();
      if ($filePreview
        ->exists()) {
        $this->m_confilictsErrors[] = Message::createMessage(Message::FILE_ALREADY_EXISTS, $filePreview
          ->getName());
      }
    }
  }
  public function uploadAndCommit($file) {
    $initName = $this
      ->getName();
    $this
      ->setFreeFileName();
    if (!move_uploaded_file($file['tmp_name'], $this
      ->getFullPath())) {
      throw new MessageException(Message::createMessage(Message::WRITING_FILE_ERROR, $initName));
    }
  }
  public function rehost($url) {
    $dUrl = URLDownloader::download($url, $this
      ->getBaseDir() . "/" . $this
      ->getDir());
    $this
      ->setName($dUrl->fileName);
  }
  public function commit($dir, $autoRename) {
    $file = $this
      ->getCommitedFile($dir);
    if ($autoRename) {
      $file
        ->setFreeFileName();
    }
    $this
      ->copyTo($file);
    return $file;
  }
  public function isCommited() {
    return false;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AFile::$m_commonErrors protected property
AFile::$m_config protected property
AFile::$m_dir private property
AFile::$m_name private property
AFile::copyTo public function
AFile::delete public function
AFile::exists public function
AFile::getData public function
AFile::getDir public function
AFile::getExt public function
AFile::getFullPath public function
AFile::getImage public function
AFile::getImageHeight public function
AFile::getImageWidth public function
AFile::getModificationName public function 1
AFile::getModifications public function 1
AFile::getName public function
AFile::getNameWithoutExt public function
AFile::getPath public function
AFile::getSize public function
AFile::isImage public function
AFile::setDir public function
AFile::setFreeFileName protected function
AFile::setName public function
FileUploaded::$m_confilictsErrors protected property
FileUploaded::$m_customErrors protected property
FileUploaded::$m_newName protected property
FileUploaded::addCustomError public function
FileUploaded::checkForConflicts public function
FileUploaded::checkForErrors public function Overrides AFile::checkForErrors
FileUploaded::commit public function
FileUploaded::getBaseDir public function Overrides AFile::getBaseDir
FileUploaded::getCommitedFile public function
FileUploaded::getErrors public function Overrides AFile::getErrors
FileUploaded::getNewName public function
FileUploaded::isCommited public function Overrides AFile::isCommited
FileUploaded::rehost public function
FileUploaded::uploadAndCommit public function
FileUploaded::__construct public function Overrides AFile::__construct