web/lib/Zend/File/Transfer/Adapter/Abstract.php
changeset 1230 68c69c656a2c
parent 807 877f952ae2bd
equal deleted inserted replaced
1229:5a6b6e770365 1230:68c69c656a2c
    12  * obtain it through the world-wide-web, please send an email
    12  * obtain it through the world-wide-web, please send an email
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category  Zend
    15  * @category  Zend
    16  * @package   Zend_File_Transfer
    16  * @package   Zend_File_Transfer
    17  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    17  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @license   http://framework.zend.com/license/new-bsd     New BSD License
    18  * @license   http://framework.zend.com/license/new-bsd     New BSD License
    19  * @version   $Id: Abstract.php 24593 2012-01-05 20:35:02Z matthew $
    19  * @version   $Id$
    20  */
    20  */
    21 
    21 
    22 /**
    22 /**
    23  * Abstract class for file transfers (Downloads and Uploads)
    23  * Abstract class for file transfers (Downloads and Uploads)
    24  *
    24  *
    25  * @category  Zend
    25  * @category  Zend
    26  * @package   Zend_File_Transfer
    26  * @package   Zend_File_Transfer
    27  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    27  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    28  * @license   http://framework.zend.com/license/new-bsd     New BSD License
    28  * @license   http://framework.zend.com/license/new-bsd     New BSD License
    29  */
    29  */
    30 abstract class Zend_File_Transfer_Adapter_Abstract
    30 abstract class Zend_File_Transfer_Adapter_Abstract
    31 {
    31 {
    32     /**@+
    32     /**@+
   553     /**
   553     /**
   554      * Sets Options for adapters
   554      * Sets Options for adapters
   555      *
   555      *
   556      * @param array $options Options to set
   556      * @param array $options Options to set
   557      * @param array $files   (Optional) Files to set the options for
   557      * @param array $files   (Optional) Files to set the options for
       
   558      * @return Zend_File_Transfer_Adapter_Abstract
   558      */
   559      */
   559     public function setOptions($options = array(), $files = null) {
   560     public function setOptions($options = array(), $files = null) {
   560         $file = $this->_getFiles($files, false, true);
   561         $file = $this->_getFiles($files, false, true);
   561 
   562 
   562         if (is_array($options)) {
   563         if (is_array($options)) {
   934     }
   935     }
   935 
   936 
   936     /**
   937     /**
   937      * Retrieves the filename of transferred files.
   938      * Retrieves the filename of transferred files.
   938      *
   939      *
   939      * @param  string  $fileelement (Optional) Element to return the filename for
   940      * @param  string|null   $file
   940      * @param  boolean $path        (Optional) Should the path also be returned ?
   941      * @param  boolean $path (Optional) Should the path also be returned ?
   941      * @return string|array
   942      * @return string|array
   942      */
   943      */
   943     public function getFileName($file = null, $path = true)
   944     public function getFileName($file = null, $path = true)
   944     {
   945     {
   945         $files     = $this->_getFiles($file, true, true);
   946         $files     = $this->_getFiles($file, true, true);
  1030     {
  1031     {
  1031         $orig = $files;
  1032         $orig = $files;
  1032         $destination = rtrim($destination, "/\\");
  1033         $destination = rtrim($destination, "/\\");
  1033         if (!is_dir($destination)) {
  1034         if (!is_dir($destination)) {
  1034             require_once 'Zend/File/Transfer/Exception.php';
  1035             require_once 'Zend/File/Transfer/Exception.php';
  1035             throw new Zend_File_Transfer_Exception('The given destination is not a directory or does not exist');
  1036             throw new Zend_File_Transfer_Exception(
  1036         }
  1037                 'The given destination is not a directory or does not exist'
  1037 
  1038             );
  1038         if (!is_writable($destination)) {
  1039         }
       
  1040 
       
  1041         if (!$this->_isPathWriteable($destination)) {
  1039             require_once 'Zend/File/Transfer/Exception.php';
  1042             require_once 'Zend/File/Transfer/Exception.php';
  1040             throw new Zend_File_Transfer_Exception('The given destination is not writeable');
  1043             throw new Zend_File_Transfer_Exception(
       
  1044                 'The given destination is not writable'
       
  1045             );
  1041         }
  1046         }
  1042 
  1047 
  1043         if ($files === null) {
  1048         if ($files === null) {
  1044             foreach ($this->_files as $file => $content) {
  1049             foreach ($this->_files as $file => $content) {
  1045                 $this->_files[$file]['destination'] = $destination;
  1050                 $this->_files[$file]['destination'] = $destination;
  1061     /**
  1066     /**
  1062      * Retrieve destination directory value
  1067      * Retrieve destination directory value
  1063      *
  1068      *
  1064      * @param  null|string|array $files
  1069      * @param  null|string|array $files
  1065      * @return null|string|array
  1070      * @return null|string|array
       
  1071      * @throws Zend_File_Transfer_Exception
  1066      */
  1072      */
  1067     public function getDestination($files = null)
  1073     public function getDestination($files = null)
  1068     {
  1074     {
  1069         $orig  = $files;
  1075         $orig  = $files;
  1070         $files = $this->_getFiles($files, false, true);
  1076         $files = $this->_getFiles($files, false, true);
  1100     /**
  1106     /**
  1101      * Set translator object for localization
  1107      * Set translator object for localization
  1102      *
  1108      *
  1103      * @param  Zend_Translate|null $translator
  1109      * @param  Zend_Translate|null $translator
  1104      * @return Zend_File_Transfer_Abstract
  1110      * @return Zend_File_Transfer_Abstract
       
  1111      * @throws Zend_File_Transfer_Exception
  1105      */
  1112      */
  1106     public function setTranslator($translator = null)
  1113     public function setTranslator($translator = null)
  1107     {
  1114     {
  1108         if (null === $translator) {
  1115         if (null === $translator) {
  1109             $this->_translator = null;
  1116             $this->_translator = null;
  1421 
  1428 
  1422     /**
  1429     /**
  1423      * Tries to detect if we can read and write to the given path
  1430      * Tries to detect if we can read and write to the given path
  1424      *
  1431      *
  1425      * @param string $path
  1432      * @param string $path
       
  1433      * @return bool
  1426      */
  1434      */
  1427     protected function _isPathWriteable($path)
  1435     protected function _isPathWriteable($path)
  1428     {
  1436     {
  1429         $tempFile = rtrim($path, "/\\");
  1437         $tempFile = rtrim($path, "/\\");
  1430         $tempFile .= '/' . 'test.1';
  1438         $tempFile .= '/' . 'test.1';