Mage_Downloadable_Helper_File Class Reference

Inheritance diagram for Mage_Downloadable_Helper_File:

Mage_Core_Helper_Abstract

List of all members.

Public Member Functions

 moveFileFromTmp ($baseTmpPath, $basePath, $file)
 getFilePath ($path, $file)
 getFileFromPathFile ($pathFile)
 getFileType ($filePath)

Protected Member Functions

 _moveFileFromTmp ($baseTmpPath, $basePath, $file)
 _prepareFileForPath ($file)
 _getFileTypeByExt ($ext)


Detailed Description

Definition at line 34 of file File.php.


Member Function Documentation

_getFileTypeByExt ( ext  )  [protected]

Definition at line 144 of file File.php.

00145     {
00146         $type = Mage::getConfig()->getNode('global/mime/types/x' . $ext);
00147         if ($type) {
00148             return $type;
00149         }
00150         return 'application/octet-stream';
00151     }

_moveFileFromTmp ( baseTmpPath,
basePath,
file 
) [protected]

Move file from tmp path to base path

Parameters:
string $baseTmpPath
string $basePath
string $file
Returns:
string

Definition at line 70 of file File.php.

00071     {
00072         $ioObject = new Varien_Io_File();
00073         $destDirectory = dirname($this->getFilePath($basePath, $file));
00074         try {
00075             $ioObject->open(array('path'=>$destDirectory));
00076         } catch (Exception $e) {
00077             $ioObject->mkdir($destDirectory, 0777, true);
00078             $ioObject->open(array('path'=>$destDirectory));
00079         }
00080 
00081         if (strrpos($file, '.tmp') == strlen($file)-4) {
00082             $file = substr($file, 0, strlen($file)-4);
00083         }
00084 
00085         $destFile = dirname($file) . $ioObject->dirsep()
00086                   . Varien_File_Uploader::getNewFileName($this->getFilePath($basePath, $file));
00087         $result = $ioObject->mv(
00088             $this->getFilePath($baseTmpPath, $file),
00089             $this->getFilePath($basePath, $destFile)
00090         );
00091         return str_replace($ioObject->dirsep(), '/', $destFile);
00092     }

_prepareFileForPath ( file  )  [protected]

Replace slashes with directory separator

Parameters:
string $file
Returns:
string

Definition at line 118 of file File.php.

00119     {
00120         return str_replace('/', DS, $file);
00121     }

getFileFromPathFile ( pathFile  ) 

Return file name form file path

Parameters:
string $pathFile
Returns:
string

Definition at line 129 of file File.php.

00130     {
00131         $file = '';
00132 
00133         $file = substr($pathFile, strrpos($this->_prepareFileForPath($pathFile), DS)+1);
00134 
00135         return $file;
00136     }

getFilePath ( path,
file 
)

Return full path to file

Parameters:
string $path
string $file
Returns:
string

Definition at line 101 of file File.php.

00102     {
00103         $file = $this->_prepareFileForPath($file);
00104 
00105         if(substr($file, 0, 1) == DS) {
00106             return $path . DS . substr($file, 1);
00107         }
00108 
00109         return $path . DS . $file;
00110     }

getFileType ( filePath  ) 

Definition at line 138 of file File.php.

00139     {
00140         $ext = substr($filePath, strrpos($filePath, '.')+1);
00141         return $this->_getFileTypeByExt($ext);
00142     }

moveFileFromTmp ( baseTmpPath,
basePath,
file 
)

Checking file for moving and move it

Parameters:
string $baseTmpPath
string $basePath
array $file
Returns:
string

Definition at line 44 of file File.php.

00045     {
00046         if (isset($file[0])) {
00047             $fileName = $file[0]['file'];
00048             if ($file[0]['status'] == 'new') {
00049                 try {
00050                     $fileName = $this->_moveFileFromTmp(
00051                         $baseTmpPath, $basePath, $file[0]['file']
00052                     );
00053                 } catch (Exception $e) {
00054                     Mage::throwException(Mage::helper('downloadable')->__('An error occurred while saving the file(s).'));
00055                 }
00056             }
00057             return $fileName;
00058         }
00059         return '';
00060     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:08 2009 for Magento by  doxygen 1.5.8