class FileUploadedQuick in N1ED - Visual editor as CKEditor plugin with Bootstrap support 8.2
Hierarchy
- class \Drupal\n1ed\Flmngr\FileUploaderServer\lib\file\AFile
- class \Drupal\n1ed\Flmngr\FileUploaderServer\lib\file\FileUploadedQuick
Expanded class hierarchy of FileUploadedQuick
1 file declares its use of FileUploadedQuick
- ActionQuickUpload.php in src/
Flmngr/ FileUploaderServer/ lib/ action/ ActionQuickUpload.php
File
- src/
Flmngr/ FileUploaderServer/ lib/ file/ FileUploadedQuick.php, line 16
Namespace
Drupal\n1ed\Flmngr\FileUploaderServer\lib\fileView source
class FileUploadedQuick extends AFile {
protected $m_newName;
protected $m_confilictsErrors = [];
protected $m_customErrors = [];
protected $dir;
protected $name;
protected $relativePath;
public function __construct($config, $dir, $name, $newName, $relativePath) {
parent::__construct($config, $dir, $name);
$this->dir = $dir;
$this->name = $name;
$this->m_newName = $newName;
$this->name = $this
->checkFileNameExistence();
$this->relativePath = $relativePath;
}
private function checkFileNameExistence() {
function file_newname($path, $filename) {
if ($pos = strrpos($filename, '.')) {
$name = substr($filename, 0, $pos);
$ext = substr($filename, $pos);
}
else {
$name = $filename;
}
$newpath = $path . '/' . $filename;
$newname = $filename;
$counter = 0;
while (file_exists($newpath)) {
$newname = $name . '_' . $counter . $ext;
$newpath = $path . '/' . $newname;
$counter++;
}
return $newname;
}
return file_newname($this->dir, $this->name);
}
public function getBaseDir() {
return $this->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->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 upload($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 isCommited() {
return true;
}
public function getFullPath() {
return $this->dir . '/' . $this->name;
}
public function getData() {
$data = new FileData();
$data->name = $this->name;
$data->dir = $this->relativePath;
$data->bytes = $this
->getSize();
$errors = $this
->getErrors();
$data->errors = [];
for ($i = 0; $i < count($errors); $i++) {
$data->errors[] = (array) $errors[$i];
}
$data->isImage = $this
->isImage();
$data->sizes = [];
if ($data->isImage) {
$data->width = $this
->getImageWidth();
$data->height = $this
->getImageHeight();
}
return $data;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AFile:: |
protected | property | ||
AFile:: |
protected | property | ||
AFile:: |
public | function | Copies file to another place. | |
AFile:: |
public | function | Deletes file from storage. | |
AFile:: |
public | function | Does file exist. | |
AFile:: |
public | function | Gets directory. | |
AFile:: |
public | function | Gets extension of file. | |
AFile:: |
public | function | Gets as image object. | |
AFile:: |
public | function | Gets height of image. | |
AFile:: |
public | function | Gets width of image. | |
AFile:: |
public | function | Gets modification name. | 1 |
AFile:: |
public | function | Gets all file modifications (original, preview, etc.). | 1 |
AFile:: |
public | function | Gets name. | |
AFile:: |
public | function | Gets a name without extension. | |
AFile:: |
public | function | Gets path. | |
AFile:: |
public | function | Gets a size of file. | |
AFile:: |
public | function | Checks file is image or not. | |
AFile:: |
public | function | Sets a directory of file. | |
AFile:: |
protected | function | Generates and sets free file name for this file. | |
AFile:: |
public | function | Sets a name of file. | |
FileUploadedQuick:: |
protected | property |
Overrides AFile:: |
|
FileUploadedQuick:: |
protected | property | ||
FileUploadedQuick:: |
protected | property | ||
FileUploadedQuick:: |
protected | property | ||
FileUploadedQuick:: |
protected | property |
Overrides AFile:: |
|
FileUploadedQuick:: |
protected | property | ||
FileUploadedQuick:: |
public | function | ||
FileUploadedQuick:: |
private | function | ||
FileUploadedQuick:: |
public | function | ||
FileUploadedQuick:: |
public | function |
Returns do we need to continue check or not. Overrides AFile:: |
|
FileUploadedQuick:: |
public | function |
Gets base directory. Overrides AFile:: |
|
FileUploadedQuick:: |
public | function | ||
FileUploadedQuick:: |
public | function |
Gets a data for response format file representation. Overrides AFile:: |
|
FileUploadedQuick:: |
public | function |
Gets errors accumulated for file. Overrides AFile:: |
|
FileUploadedQuick:: |
public | function |
Gets full path. Overrides AFile:: |
|
FileUploadedQuick:: |
public | function | ||
FileUploadedQuick:: |
public | function |
Is file commited. Overrides AFile:: |
|
FileUploadedQuick:: |
public | function | ||
FileUploadedQuick:: |
public | function |
Creates a File instance. Overrides AFile:: |