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-2008 Zend Technologies USA Inc. (http://www.zend.com)
20
* @license http://framework.zend.com/license/new-bsd New BSD License
24
* @see Zend_Gdata_App_MediaData
26
require_once 'Zend/Gdata/App/BaseMediaSource.php';
29
* Concrete class to use a file handle as an attachment within a MediaEntry.
33
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
34
* @license http://framework.zend.com/license/new-bsd New BSD License
36
class Zend_Gdata_App_MediaFileSource extends Zend_Gdata_App_BaseMediaSource
39
* The filename which is represented
43
protected $_filename = null;
46
* The content type for the file attached (example image/png)
50
protected $_contentType = null;
53
* Create a new Zend_Gdata_App_MediaFileSource object.
55
* @param string $filename The name of the file to read from.
57
public function __construct($filename)
59
$this->setFilename($filename);
63
* Return the MIME multipart representation of this MediaEntry.
66
* @throws Zend_Gdata_App_IOException
68
public function encode()
70
if ($this->getFilename() !== null &&
71
is_readable($this->getFilename())) {
73
// Retrieves the file, using the include path
74
$fileHandle = fopen($this->getFilename(), 'r', true);
75
$result = fread($fileHandle, filesize($this->getFilename()));
76
if ($result === false) {
77
require_once 'Zend/Gdata/App/IOException.php';
78
throw new Zend_Gdata_App_IOException("Error reading file - " .
79
$this->getFilename() . '. Read failed.');
84
require_once 'Zend/Gdata/App/IOException.php';
85
throw new Zend_Gdata_App_IOException("Error reading file - " .
86
$this->getFilename() . '. File is not readable.');
91
* Get the filename associated with this reader.
95
public function getFilename()
97
return $this->_filename;
101
* Set the filename which is to be read.
103
* @param string $value The desired file handle.
104
* @return Zend_Gdata_App_MediaFileSource Provides a fluent interface.
106
public function setFilename($value)
108
$this->_filename = $value;
113
* The content type for the file attached (example image/png)
115
* @return string The content type
117
public function getContentType()
119
return $this->_contentType;
123
* Set the content type for the file attached (example image/png)
125
* @param string $value The content type
126
* @return Zend_Gdata_App_MediaFileSource Provides a fluent interface
128
public function setContentType($value)
130
$this->_contentType = $value;
135
* Alias for getFilename().
139
public function __toString()
141
return $this->getFilename();