File indexing completed on 2025-03-02 05:29:26
0001 <?php 0002 0003 /** 0004 * Zend Framework 0005 * 0006 * LICENSE 0007 * 0008 * This source file is subject to the new BSD license that is bundled 0009 * with this package in the file LICENSE.txt. 0010 * It is also available through the world-wide-web at this URL: 0011 * http://framework.zend.com/license/new-bsd 0012 * If you did not receive a copy of the license and are unable to 0013 * obtain it through the world-wide-web, please send an email 0014 * to license@zend.com so we can send you a copy immediately. 0015 * 0016 * @category Zend 0017 * @package Zend_Gdata 0018 * @subpackage App 0019 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0020 * @license http://framework.zend.com/license/new-bsd New BSD License 0021 * @version $Id$ 0022 */ 0023 0024 /** 0025 * @see Zend_Gdata_App_MediaData 0026 */ 0027 // require_once 'Zend/Gdata/App/BaseMediaSource.php'; 0028 0029 /** 0030 * Concrete class to use a file handle as an attachment within a MediaEntry. 0031 * 0032 * @category Zend 0033 * @package Zend_Gdata 0034 * @subpackage App 0035 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0036 * @license http://framework.zend.com/license/new-bsd New BSD License 0037 */ 0038 class Zend_Gdata_App_MediaFileSource extends Zend_Gdata_App_BaseMediaSource 0039 { 0040 /** 0041 * The filename which is represented 0042 * 0043 * @var string 0044 */ 0045 protected $_filename = null; 0046 0047 /** 0048 * The content type for the file attached (example image/png) 0049 * 0050 * @var string 0051 */ 0052 protected $_contentType = null; 0053 0054 /** 0055 * Create a new Zend_Gdata_App_MediaFileSource object. 0056 * 0057 * @param string $filename The name of the file to read from. 0058 */ 0059 public function __construct($filename) 0060 { 0061 $this->setFilename($filename); 0062 } 0063 0064 /** 0065 * Return the MIME multipart representation of this MediaEntry. 0066 * 0067 * @return string 0068 * @throws Zend_Gdata_App_IOException 0069 */ 0070 public function encode() 0071 { 0072 if ($this->getFilename() !== null && 0073 is_readable($this->getFilename())) { 0074 0075 // Retrieves the file, using the include path 0076 $fileHandle = fopen($this->getFilename(), 'r', true); 0077 $result = fread($fileHandle, filesize($this->getFilename())); 0078 if ($result === false) { 0079 // require_once 'Zend/Gdata/App/IOException.php'; 0080 throw new Zend_Gdata_App_IOException("Error reading file - " . 0081 $this->getFilename() . '. Read failed.'); 0082 } 0083 fclose($fileHandle); 0084 return $result; 0085 } else { 0086 // require_once 'Zend/Gdata/App/IOException.php'; 0087 throw new Zend_Gdata_App_IOException("Error reading file - " . 0088 $this->getFilename() . '. File is not readable.'); 0089 } 0090 } 0091 0092 /** 0093 * Get the filename associated with this reader. 0094 * 0095 * @return string 0096 */ 0097 public function getFilename() 0098 { 0099 return $this->_filename; 0100 } 0101 0102 /** 0103 * Set the filename which is to be read. 0104 * 0105 * @param string $value The desired file handle. 0106 * @return Zend_Gdata_App_MediaFileSource Provides a fluent interface. 0107 */ 0108 public function setFilename($value) 0109 { 0110 $this->_filename = $value; 0111 return $this; 0112 } 0113 0114 /** 0115 * The content type for the file attached (example image/png) 0116 * 0117 * @return string The content type 0118 */ 0119 public function getContentType() 0120 { 0121 return $this->_contentType; 0122 } 0123 0124 /** 0125 * Set the content type for the file attached (example image/png) 0126 * 0127 * @param string $value The content type 0128 * @return Zend_Gdata_App_MediaFileSource Provides a fluent interface 0129 */ 0130 public function setContentType($value) 0131 { 0132 $this->_contentType = $value; 0133 return $this; 0134 } 0135 0136 /** 0137 * Alias for getFilename(). 0138 * 0139 * @return string 0140 */ 0141 public function __toString() 0142 { 0143 return $this->getFilename(); 0144 } 0145 0146 }