protected function initDiskPath() { if ($this->record['fileCategory'] == 'image') { $request = CoreServices2::getRequest(); $width = $request->getFromGet('width'); $height = $request->getFromGet('height'); $ignoreProportions = $request->getFromGet('ignoreProportions'); $crop = $request->getFromGet('crop'); $backgroundColor = $request->getFromGet('backgroundColor'); $keepSmall = $request->getFromGet('keepSmall'); } $files = CoreServices2::getFiles(); if (empty($width) && empty($height)) { $this->diskPath = $files->getDiskPath($this->record['fileBaseName'], $this->record['fileExtension']); } else { $options = array('width' => $width, 'height' => $height, 'ignoreProportions' => $ignoreProportions, 'crop' => $crop, 'backgroundColor' => $backgroundColor, 'keepSmall' => $keepSmall); $this->diskPath = $files->getResizedImageDiskPath($this->record['fileBaseName'], $this->record['fileExtension'], $options); if (!is_file($this->diskPath)) { $files->resizeImage($this->diskPath, $this->record['fileBaseName'], $this->record['fileExtension'], $options); } } if (!is_file($this->diskPath)) { $this->error(3); } }
public function validate($messageManager) { $field = $this->form->getField($this->fieldName); $fieldCaption = $field->getCaption(); $uploadStruct = $field->getValue(); if (empty($uploadStruct)) { $recordId = empty($this->idFieldName) ? null : $this->form->getField($this->idFieldName)->getValue(); if (empty($recordId)) { $messageManager->addMessage('fileNotUploaded', array($this->fieldName => $fieldCaption)); } } elseif (!empty($uploadStruct['error']) && $uploadStruct['error'] != UPLOAD_ERR_OK) { $message = $this->decodePHPUploadError($uploadStruct['error']); $messageManager->addMessage($message, array($this->fieldName => $fieldCaption)); } else { $extension = CoreServices2::getFiles()->checkTypeAndGetExtension($uploadStruct, $this->fileCategory); if (empty($extension)) { $messageManager->addMessage('invalidFileType_' . $this->fileCategory, array($this->fieldName => $fieldCaption)); } if (CoreServices2::getFiles()->getMaxFileSize() < $uploadStruct['size']) { $messageManager->addMessage('fileTooBig', array($this->fieldName => $fieldCaption)); } } }
protected function deleteDiskFile(&$record) { if ($record['fileBaseName']) { CoreServices2::getFiles()->removeFile($record['fileBaseName'], $record['fileExtension'], $record['fileCategory'] == 'image'); $record['fileBaseName'] = null; $record['fileExtension'] = null; $record['fileMimeType'] = null; } }