Theme Image Uploader
Definition at line 11 of file Uploader.php.
◆ __construct()
Constructor
- Parameters
-
\Magento\Framework\Filesystem | $filesystem | |
\Magento\Framework\HTTP\Adapter\FileTransferFactory | $adapterFactory | |
\Magento\Framework\File\UploaderFactory | $uploaderFactory | |
Definition at line 48 of file Uploader.php.
54 $this->_transferAdapter = $adapterFactory->create();
55 $this->_uploaderFactory = $uploaderFactory;
◆ uploadPreviewImage()
uploadPreviewImage |
( |
|
$scope, |
|
|
|
$destinationPath |
|
) |
| |
Upload preview image
- Parameters
-
string | $scope | the request key for file |
string | $destinationPath | path to upload directory |
- Returns
- bool
- Exceptions
-
Definition at line 66 of file Uploader.php.
68 if (!$this->_transferAdapter->isUploaded($scope)) {
71 if (!$this->_transferAdapter->isValid($scope)) {
72 throw new \Magento\Framework\Exception\LocalizedException(
73 new \
Magento\Framework\Phrase(
'Uploaded image is not valid')
76 $upload = $this->_uploaderFactory->create([
'fileId' => $scope]);
77 $upload->setAllowCreateFolders(
true);
78 $upload->setAllowedExtensions($this->_allowedExtensions);
79 $upload->setAllowRenameFiles(
true);
80 $upload->setFilesDispersion(
false);
82 if (!$upload->checkAllowedExtension($upload->getFileExtension())) {
83 throw new \Magento\Framework\Exception\LocalizedException(
84 new \
Magento\Framework\Phrase(
'Invalid image file type.')
87 if (!$upload->save($destinationPath)) {
88 throw new \Magento\Framework\Exception\LocalizedException(
89 new \
Magento\Framework\Phrase(
'Image can not be saved.')
92 return $destinationPath .
'/' . $upload->getUploadedFileName();
◆ $_allowedExtensions
$_allowedExtensions = ['jpg', 'jpeg', 'gif', 'png', 'xbm', 'wbmp'] |
|
protected |
◆ $_filesystem
◆ $_transferAdapter
◆ $_uploaderFactory
The documentation for this class was generated from the following file:
- vendor/magento/framework/View/Design/Theme/Image/Uploader.php