当前位置: 首页>>代码示例>>PHP>>正文


PHP WriteInterface::renameFile方法代码示例

本文整理汇总了PHP中Magento\Framework\Filesystem\Directory\WriteInterface::renameFile方法的典型用法代码示例。如果您正苦于以下问题:PHP WriteInterface::renameFile方法的具体用法?PHP WriteInterface::renameFile怎么用?PHP WriteInterface::renameFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\Filesystem\Directory\WriteInterface的用法示例。


在下文中一共展示了WriteInterface::renameFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _moveFileFromTmp

 /**
  * Move file from tmp path to base path
  *
  * @param string $baseTmpPath
  * @param string $basePath
  * @param string $file
  * @return string
  */
 protected function _moveFileFromTmp($baseTmpPath, $basePath, $file)
 {
     if (strrpos($file, '.tmp') == strlen($file) - 4) {
         $file = substr($file, 0, strlen($file) - 4);
     }
     $destFile = dirname($file) . '/' . \Magento\Core\Model\File\Uploader::getNewFileName($this->getFilePath($basePath, $file));
     $this->_coreFileStorageDatabase->copyFile($this->getFilePath($baseTmpPath, $file), $this->getFilePath($basePath, $destFile));
     $this->_mediaDirectory->renameFile($this->getFilePath($baseTmpPath, $file), $this->getFilePath($basePath, $destFile));
     return str_replace('\\', '/', $destFile);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:18,代码来源:File.php

示例2: moveImageFromTmp

 /**
  * Move image from temporary directory to normal
  *
  * @param string $file
  * @return string
  */
 protected function moveImageFromTmp($file)
 {
     $file = $this->getFilenameFromTmp($file);
     $destinationFile = $this->getUniqueFileName($file);
     if ($this->fileStorageDb->checkDbUsage()) {
         $this->fileStorageDb->renameFile($this->mediaConfig->getTmpMediaShortUrl($file), $this->mediaConfig->getMediaShortUrl($destinationFile));
         $this->mediaDirectory->delete($this->mediaConfig->getTmpMediaPath($file));
         $this->mediaDirectory->delete($this->mediaConfig->getMediaPath($destinationFile));
     } else {
         $this->mediaDirectory->renameFile($this->mediaConfig->getTmpMediaPath($file), $this->mediaConfig->getMediaPath($destinationFile));
     }
     return str_replace('\\', '/', $destinationFile);
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:19,代码来源:CreateHandler.php

示例3: addImage

 /**
  * Add image to media gallery and return new filename
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param string $file file path of image in file system
  * @param string|string[] $mediaAttribute code of attribute with type 'media_image',
  *                                                      leave blank if image should be only in gallery
  * @param boolean $move if true, it will move source file
  * @param boolean $exclude mark image as disabled in product page view
  * @return string
  * @throws \Magento\Framework\Exception\LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function addImage(\Magento\Catalog\Model\Product $product, $file, $mediaAttribute = null, $move = false, $exclude = true)
 {
     $file = $this->mediaDirectory->getRelativePath($file);
     if (!$this->mediaDirectory->isFile($file)) {
         throw new LocalizedException(__('The image does not exist.'));
     }
     $pathinfo = pathinfo($file);
     $imgExtensions = ['jpg', 'jpeg', 'gif', 'png'];
     if (!isset($pathinfo['extension']) || !in_array(strtolower($pathinfo['extension']), $imgExtensions)) {
         throw new LocalizedException(__('Please correct the image file type.'));
     }
     $fileName = \Magento\MediaStorage\Model\File\Uploader::getCorrectFileName($pathinfo['basename']);
     $dispretionPath = \Magento\MediaStorage\Model\File\Uploader::getDispretionPath($fileName);
     $fileName = $dispretionPath . '/' . $fileName;
     $fileName = $this->getNotDuplicatedFilename($fileName, $dispretionPath);
     $destinationFile = $this->mediaConfig->getTmpMediaPath($fileName);
     try {
         /** @var $storageHelper \Magento\MediaStorage\Helper\File\Storage\Database */
         $storageHelper = $this->fileStorageDb;
         if ($move) {
             $this->mediaDirectory->renameFile($file, $destinationFile);
             //If this is used, filesystem should be configured properly
             $storageHelper->saveFile($this->mediaConfig->getTmpMediaShortUrl($fileName));
         } else {
             $this->mediaDirectory->copyFile($file, $destinationFile);
             $storageHelper->saveFile($this->mediaConfig->getTmpMediaShortUrl($fileName));
             $this->mediaDirectory->changePermissions($destinationFile, DriverInterface::WRITEABLE_FILE_MODE);
         }
     } catch (\Exception $e) {
         throw new LocalizedException(__('We couldn\'t move this file: %1.', $e->getMessage()));
     }
     $fileName = str_replace('\\', '/', $fileName);
     $attrCode = $this->getAttribute()->getAttributeCode();
     $mediaGalleryData = $product->getData($attrCode);
     $position = 0;
     if (!is_array($mediaGalleryData)) {
         $mediaGalleryData = ['images' => []];
     }
     foreach ($mediaGalleryData['images'] as &$image) {
         if (isset($image['position']) && $image['position'] > $position) {
             $position = $image['position'];
         }
     }
     $position++;
     $mediaGalleryData['images'][] = ['file' => $fileName, 'position' => $position, 'label' => '', 'disabled' => (int) $exclude];
     $product->setData($attrCode, $mediaGalleryData);
     if ($mediaAttribute !== null) {
         $this->setMediaAttribute($product, $mediaAttribute, $fileName);
     }
     return $fileName;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:65,代码来源:AbstractMedia.php

示例4: moveFileFromTmp

 /**
  * Checking file for moving and move it
  *
  * @param string $imageName
  *
  * @return string
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function moveFileFromTmp($imageName)
 {
     $baseTmpPath = $this->getBaseTmpPath();
     $basePath = $this->getBasePath();
     $baseImagePath = $this->getFilePath($basePath, $imageName);
     $baseTmpImagePath = $this->getFilePath($baseTmpPath, $imageName);
     try {
         $this->coreFileStorageDatabase->copyFile($baseTmpImagePath, $baseImagePath);
         $this->mediaDirectory->renameFile($baseTmpImagePath, $baseImagePath);
     } catch (\Exception $e) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Something went wrong while saving the file(s).'));
     }
     return $imageName;
 }
开发者ID:ant-workaholic,项目名称:Store-locator,代码行数:23,代码来源:ImageUploader.php

示例5: _moveImageFromTmp

 /**
  * Move image from temporary directory to normal
  *
  * @param string $file
  * @return string
  */
 protected function _moveImageFromTmp($file)
 {
     $file = $this->getFilenameFromTmp($file);
     $destinationFile = $this->_getUniqueFileName($file);
     /** @var $storageHelper \Magento\MediaStorage\Helper\File\Storage\Database */
     $storageHelper = $this->_fileStorageDb;
     if ($storageHelper->checkDbUsage()) {
         $storageHelper->renameFile($this->_mediaConfig->getTmpMediaShortUrl($file), $this->_mediaConfig->getMediaShortUrl($destinationFile));
         $this->_mediaDirectory->delete($this->_mediaConfig->getTmpMediaPath($file));
         $this->_mediaDirectory->delete($this->_mediaConfig->getMediaPath($destinationFile));
     } else {
         $this->_mediaDirectory->renameFile($this->_mediaConfig->getTmpMediaPath($file), $this->_mediaConfig->getMediaPath($destinationFile));
     }
     return str_replace('\\', '/', $destinationFile);
 }
开发者ID:nja78,项目名称:magento2,代码行数:21,代码来源:Media.php

示例6: moveImageFromTmp

 /**
  * move image from tmp to catalog dir
  *
  * @param string $file
  * @return string path
  */
 public function moveImageFromTmp($file)
 {
     if (strrpos($file, '.tmp') == strlen($file) - 4) {
         $file = substr($file, 0, strlen($file) - 4);
     }
     $destinationFile = $this->getUniqueFileName($file);
     /** @var $storageHelper \Magento\MediaStorage\Helper\File\Storage\Database */
     $storageHelper = $this->fileStorageDb;
     if ($storageHelper->checkDbUsage()) {
         $storageHelper->renameFile($this->mediaConfig->getTmpMediaShortUrl($file), $this->mediaConfig->getMediaShortUrl($destinationFile));
         $this->mediaDirectory->delete($this->mediaConfig->getTmpMediaPath($file));
         $this->mediaDirectory->delete($this->getAttributeSwatchPath($destinationFile));
     } else {
         $this->mediaDirectory->renameFile($this->mediaConfig->getTmpMediaPath($file), $this->getAttributeSwatchPath($destinationFile));
     }
     return str_replace('\\', '/', $destinationFile);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:23,代码来源:Media.php


注:本文中的Magento\Framework\Filesystem\Directory\WriteInterface::renameFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。