本文整理汇总了PHP中Magento\Framework\Filesystem\Directory\WriteInterface::copyFile方法的典型用法代码示例。如果您正苦于以下问题:PHP WriteInterface::copyFile方法的具体用法?PHP WriteInterface::copyFile怎么用?PHP WriteInterface::copyFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Filesystem\Directory\WriteInterface
的用法示例。
在下文中一共展示了WriteInterface::copyFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _moveFile
/**
* Move files from TMP folder into destination folder
*
* @param string $tmpPath
* @param string $destPath
* @return bool
*/
protected function _moveFile($tmpPath, $destPath)
{
if ($this->_directory->isFile($tmpPath)) {
return $this->_directory->copyFile($tmpPath, $destPath);
} else {
return false;
}
}
示例2: duplicateImageFromTmp
/**
* Duplicate temporary images
*
* @param string $file
* @return string
*/
public function duplicateImageFromTmp($file)
{
$file = $this->getFilenameFromTmp($file);
$destinationFile = $this->getUniqueFileName($file, true);
if ($this->fileStorageDb->checkDbUsage()) {
$this->fileStorageDb->copyFile($this->mediaDirectory->getAbsolutePath($this->mediaConfig->getTmpMediaShortUrl($file)), $this->mediaConfig->getTmpMediaShortUrl($destinationFile));
} else {
$this->mediaDirectory->copyFile($this->mediaConfig->getTmpMediaPath($file), $this->mediaConfig->getTmpMediaPath($destinationFile));
}
return str_replace('\\', '/', $destinationFile);
}
示例3: _moveFile
/**
* Move files from TMP folder into destination folder
*
* @param string $tmpPath
* @param string $destPath
* @return bool
*/
protected function _moveFile($tmpPath, $destPath)
{
if ($this->_directory->isFile($tmpPath)) {
$tmpRealPath = $this->_directory->getDriver()->getRealPath($this->_directory->getAbsolutePath($tmpPath));
$destinationRealPath = $this->_directory->getDriver()->getRealPath($this->_directory->getAbsolutePath($destPath));
$isSameFile = $tmpRealPath === $destinationRealPath;
return $isSameFile ?: $this->_directory->copyFile($tmpPath, $destPath);
} else {
return false;
}
}
示例4: _copyImage
/**
* Copy image and return new filename.
*
* @param string $file
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _copyImage($file)
{
try {
$destinationFile = $this->_getUniqueFileName($file);
if (!$this->_mediaDirectory->isFile($this->_mediaConfig->getMediaPath($file))) {
throw new \Exception();
}
if ($this->_fileStorageDb->checkDbUsage()) {
$this->_fileStorageDb->copyFile($this->_mediaDirectory->getAbsolutePath($this->_mediaConfig->getMediaShortUrl($file)), $this->_mediaConfig->getMediaShortUrl($destinationFile));
$this->_mediaDirectory->delete($this->_mediaConfig->getMediaPath($destinationFile));
} else {
$this->_mediaDirectory->copyFile($this->_mediaConfig->getMediaPath($file), $this->_mediaConfig->getMediaPath($destinationFile));
}
return str_replace('\\', '/', $destinationFile);
} catch (\Exception $e) {
$file = $this->_mediaConfig->getMediaPath($file);
throw new LocalizedException(__('We couldn\'t copy file %1. Please delete media with non-existing images and try again.', $file));
}
}
示例5: createPreviewImageCopy
/**
* Create preview image duplicate
*
* @param ThemeInterface $theme
* @return bool
*/
public function createPreviewImageCopy(ThemeInterface $theme)
{
$previewDir = $this->themeImagePath->getImagePreviewDirectory();
$sourcePath = $theme->getThemeImage()->getPreviewImagePath();
$sourceRelativePath = $this->rootDirectory->getRelativePath($sourcePath);
if (!$theme->getPreviewImage() && !$this->mediaDirectory->isExist($sourceRelativePath)) {
return false;
}
$isCopied = false;
try {
$destinationFileName = \Magento\Framework\File\Uploader::getNewFileName($sourcePath);
$targetRelativePath = $this->mediaDirectory->getRelativePath($previewDir . '/' . $destinationFileName);
$isCopied = $this->rootDirectory->copyFile($sourceRelativePath, $targetRelativePath, $this->mediaDirectory);
$this->theme->setPreviewImage($destinationFileName);
} catch (\Magento\Framework\Filesystem\FilesystemException $e) {
$this->theme->setPreviewImage(null);
$this->logger->critical($e);
}
return $isCopied;
}
示例6: publishFile
/**
* Publish file
*
* @param WriteInterface $rootDir
* @param WriteInterface $targetDir
* @param string $sourcePath
* @param string $destinationPath
* @return bool
*/
public function publishFile(WriteInterface $rootDir, WriteInterface $targetDir, $sourcePath, $destinationPath)
{
return $rootDir->copyFile($sourcePath, $destinationPath, $targetDir);
}