8 * This source file is subject to the new BSD license that is bundled
9 * with this package in the file LICENSE.txt.
10 * It is also available through the world-wide-web at this URL:
11 * http://framework.zend.com/license/new-bsd
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@zend.com so we can send you a copy immediately.
19 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
25 * @see Zend_Gdata_App_MediaData
27 require_once 'Zend/Gdata/App/BaseMediaSource.php';
30 * Concrete class to use a file handle as an attachment within a MediaEntry.
35 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
36 * @license http://framework.zend.com/license/new-bsd New BSD License
38 class Zend_Gdata_App_MediaFileSource extends Zend_Gdata_App_BaseMediaSource
41 * The filename which is represented
45 protected $_filename = null;
48 * The content type for the file attached (example image/png)
52 protected $_contentType = null;
55 * Create a new Zend_Gdata_App_MediaFileSource object.
57 * @param string $filename The name of the file to read from.
59 public function __construct($filename)
61 $this->setFilename($filename);
65 * Return the MIME multipart representation of this MediaEntry.
68 * @throws Zend_Gdata_App_IOException
70 public function encode()
72 if ($this->getFilename() !== null &&
73 is_readable($this->getFilename())) {
75 // Retrieves the file, using the include path
76 $fileHandle = fopen($this->getFilename(), 'r', true);
77 $result = fread($fileHandle, filesize($this->getFilename()));
78 if ($result === false) {
79 require_once 'Zend/Gdata/App/IOException.php';
80 throw new Zend_Gdata_App_IOException("Error reading file - " .
81 $this->getFilename() . '. Read failed.');
86 require_once 'Zend/Gdata/App/IOException.php';
87 throw new Zend_Gdata_App_IOException("Error reading file - " .
88 $this->getFilename() . '. File is not readable.');
93 * Get the filename associated with this reader.
97 public function getFilename()
99 return $this->_filename;
103 * Set the filename which is to be read.
105 * @param string $value The desired file handle.
106 * @return Zend_Gdata_App_MediaFileSource Provides a fluent interface.
108 public function setFilename($value)
110 $this->_filename = $value;
115 * The content type for the file attached (example image/png)
117 * @return string The content type
119 public function getContentType()
121 return $this->_contentType;
125 * Set the content type for the file attached (example image/png)
127 * @param string $value The content type
128 * @return Zend_Gdata_App_MediaFileSource Provides a fluent interface
130 public function setContentType($value)
132 $this->_contentType = $value;
137 * Alias for getFilename().
141 public function __toString()
143 return $this->getFilename();