示例#1
0
 /**
  * Move file from tmp path to base path
  *
  * @param string $baseTmpPath
  * @param string $basePath
  * @param string $file
  * @return string
  */
 public function moveFileFromTmp($baseTmpPath, $basePath, $file)
 {
     $ioObject = new Varien_Io_File();
     $destDirectory = dirname($this->getFilePath($basePath, $file));
     try {
         $ioObject->open(array('path' => $destDirectory));
     } catch (Exception $e) {
         $ioObject->mkdir($destDirectory, 0777, true);
         $ioObject->open(array('path' => $destDirectory));
     }
     if (strrpos($file, '.tmp') == strlen($file) - 4) {
         $file = substr($file, 0, strlen($file) - 4);
     }
     $destFile = dirname($file) . $ioObject->dirsep() . Varien_File_Uploader::getNewFileName($this->getFilePath($basePath, $file));
     $result = $ioObject->mv($this->getFilePath($baseTmpPath, $file), $this->getFilePath($basePath, $file));
     return str_replace($ioObject->dirsep(), '/', $destFile);
 }
示例#2
0
 protected function _copyImage($file)
 {
     try {
         $ioObject = new Varien_Io_File();
         $destDirectory = dirname($this->_getConfig()->getMediaPath($file));
         $ioObject->open(array('path' => $destDirectory));
         $destFile = $this->_getUniqueFileName($file, $ioObject->dirsep());
         if (!$ioObject->fileExists($this->_getConfig()->getMediaPath($file), true)) {
             throw new Exception('File not exists');
         }
         if ($this->_checkDb()) {
             Mage::helper('core/file_storage_database')->copyFile($this->_getConfig()->getMediaShortUrl($file), $this->_getConfig()->getMediaShortUrl($destFile));
             $ioObject->rm($this->_getConfig()->getMediaPath($destFile));
         } else {
             $ioObject->cp($this->_getConfig()->getMediaPath($file), $this->_getConfig()->getMediaPath($destFile));
         }
     } catch (Exception $e) {
         $file = $this->_getConfig()->getMediaPath($file);
         Mage::throwException(Mage::helper('ampaction')->__('Failed to copy file %s. Please, delete media with non-existing images and try again.', $file));
         $e = $e;
         // for zend debugger
     }
     return str_replace($ioObject->dirsep(), '/', $destFile);
 }
 protected function _moveFileFromTmp($baseTmpPath, $basePath, $file)
 {
     $ioObject = new Varien_Io_File();
     $destDirectory = dirname($this->getFilePath($basePath, $file));
     try {
         $ioObject->open(array('path' => $destDirectory));
     } catch (Exception $e) {
         $ioObject->mkdir($destDirectory, 0777, true);
         $ioObject->open(array('path' => $destDirectory));
     }
     if (strrpos($file, '.tmp') == strlen($file) - 4) {
         $file = substr($file, 0, strlen($file) - 4);
     }
     // DO NOT rename file if it exists. Overwrite it. Custumer request in ticket#2012120510000418 — Magento is losing connection to files
     $destFile = $file;
     //$destFile = dirname($file) . $ioObject->dirsep()
     //          . Mage_Core_Model_File_Uploader::getNewFileName($this->getFilePath($basePath, $file));
     //die ("destFile: $destFile<br>file: $file<br>basePath: $basePath<br>dirname: ".dirname($file));
     Mage::helper('core/file_storage_database')->copyFile($this->getFilePath($baseTmpPath, $file), $this->getFilePath($basePath, $destFile));
     $result = $ioObject->mv($this->getFilePath($baseTmpPath, $file), $this->getFilePath($basePath, $destFile));
     return str_replace($ioObject->dirsep(), '/', $destFile);
 }
示例#4
0
 /**
  * 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)
 {
     $ioObject = new Varien_Io_File();
     $destDirectory = dirname($this->getFilePath($basePath, $file));
     try {
         $ioObject->open(array('path' => $destDirectory));
     } catch (Exception $e) {
         $ioObject->mkdir($destDirectory, 0777, true);
         $ioObject->open(array('path' => $destDirectory));
     }
     if (strrpos($file, '.tmp') == strlen($file) - 4) {
         $file = substr($file, 0, strlen($file) - 4);
     }
     $destFile = dirname($file) . $ioObject->dirsep() . Mage_Core_Model_File_Uploader::getNewFileName($this->getFilePath($basePath, $file));
     Mage::helper('Mage_Core_Helper_File_Storage_Database')->copyFile($this->getFilePath($baseTmpPath, $file), $this->getFilePath($basePath, $destFile));
     $result = $ioObject->mv($this->getFilePath($baseTmpPath, $file), $this->getFilePath($basePath, $destFile));
     return str_replace($ioObject->dirsep(), '/', $destFile);
 }
示例#5
0
 /**
  * Copy image and return new filename.
  *
  * @param string $file
  * @return string
  */
 protected function _copyImage($file)
 {
     try {
         $ioObject = new Varien_Io_File();
         $destDirectory = dirname($this->_getConfig()->getMediaPath($file));
         $ioObject->open(array('path' => $destDirectory));
         $destFile = dirname($file) . $ioObject->dirsep() . Varien_File_Uploader::getNewFileName($this->_getConfig()->getMediaPath($file));
         if (!$ioObject->fileExists($this->_getConfig()->getMediaPath($file), true)) {
             throw new Exception();
         }
         $ioObject->cp($this->_getConfig()->getMediaPath($file), $this->_getConfig()->getMediaPath($destFile));
     } catch (Exception $e) {
         Mage::throwException(Mage::helper('catalog')->__('Failed to copy file %s. Please, delete media with non-existing images and try again.', $this->_getConfig()->getMediaPath($file)));
     }
     return str_replace($ioObject->dirsep(), '/', $destFile);
 }
示例#6
0
 /**
  * Move image from temporary directory to normal
  *
  * @param string $file
  * @return string
  */
 protected function _moveImageFromTmp($file)
 {
     $ioObject = new Varien_Io_File();
     $destDirectory = dirname($this->_getConfig()->getMediaPath($file));
     try {
         $ioObject->open(array('path' => $destDirectory));
     } catch (Exception $e) {
         $ioObject->mkdir($destDirectory, 0777, true);
         $ioObject->open(array('path' => $destDirectory));
     }
     $destFile = dirname($file) . $ioObject->dirsep() . Varien_File_Uploader::getNewFileName($this->_getConfig()->getMediaPath($file));
     $ioObject->mv($this->_getConfig()->getTmpMediaPath($file), $this->_getConfig()->getMediaPath($destFile));
     return $destFile;
 }
 /**
  * Copy image from temp folder
  *
  * @param array $image
  * @return string
  */
 public function copyImage($image)
 {
     $ioObject = new Varien_Io_File();
     $file = $image['file'];
     $destDirectory = dirname($this->_getConfig()->getMediaPath($file));
     try {
         $ioObject->open(array('path' => $destDirectory));
     } catch (Exception $e) {
         $ioObject->mkdir($destDirectory, 0777, true);
         $ioObject->open(array('path' => $destDirectory));
     }
     if (strrpos($file, '.tmp') == strlen($file) - 4) {
         $file = substr($file, 0, strlen($file) - 4);
     }
     $destFile = $this->_getUniqueFileName($file, $ioObject->dirsep());
     /** @var $storageHelper Mage_Core_Helper_File_Storage_Database */
     $storageHelper = Mage::helper('core/file_storage_database');
     if ($storageHelper->checkDbUsage()) {
         $storageHelper->renameFile($this->_getConfig()->getTmpMediaShortUrl($file), $this->_getConfig()->getMediaShortUrl($destFile));
         $ioObject->rm($this->_getConfig()->getTmpMediaPath($file));
         $ioObject->rm($this->_getConfig()->getMediaPath($destFile));
     } else {
         $ioObject->mv($this->_getConfig()->getTmpMediaPath($file), $this->_getConfig()->getMediaPath($destFile));
     }
     return str_replace($ioObject->dirsep(), '/', $destFile);
 }
 /**
  * Copy image and return new filename.
  *
  * @param string $file
  * @return string
  */
 protected function _copyImage($file)
 {
     $ioObject = new Varien_Io_File();
     $destDirectory = dirname($this->_getConfig()->getMediaPath($file));
     $ioObject->open(array('path' => $destDirectory));
     $destFile = dirname($file) . $ioObject->dirsep() . Varien_File_Uploader::getNewFileName($this->_getConfig()->getMediaPath($file));
     $ioObject->cp($this->_getConfig()->getMediaPath($file), $this->_getConfig()->getMediaPath($destFile));
     return str_replace($ioObject->dirsep(), '/', $destFile);
 }