當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。