From 06f945f27840b53e57795dadbc38e76f7e11ab1c Mon Sep 17 00:00:00 2001 From: Horus3 Date: Mon, 24 Feb 2014 16:42:14 +0100 Subject: init --- zend/library/Zend/Gdata/App/MediaFileSource.php | 146 ++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 zend/library/Zend/Gdata/App/MediaFileSource.php (limited to 'zend/library/Zend/Gdata/App/MediaFileSource.php') diff --git a/zend/library/Zend/Gdata/App/MediaFileSource.php b/zend/library/Zend/Gdata/App/MediaFileSource.php new file mode 100644 index 0000000..e37bd75 --- /dev/null +++ b/zend/library/Zend/Gdata/App/MediaFileSource.php @@ -0,0 +1,146 @@ +setFilename($filename); + } + + /** + * Return the MIME multipart representation of this MediaEntry. + * + * @return string + * @throws Zend_Gdata_App_IOException + */ + public function encode() + { + if ($this->getFilename() !== null && + is_readable($this->getFilename())) { + + // Retrieves the file, using the include path + $fileHandle = fopen($this->getFilename(), 'r', true); + $result = fread($fileHandle, filesize($this->getFilename())); + if ($result === false) { + require_once 'Zend/Gdata/App/IOException.php'; + throw new Zend_Gdata_App_IOException("Error reading file - " . + $this->getFilename() . '. Read failed.'); + } + fclose($fileHandle); + return $result; + } else { + require_once 'Zend/Gdata/App/IOException.php'; + throw new Zend_Gdata_App_IOException("Error reading file - " . + $this->getFilename() . '. File is not readable.'); + } + } + + /** + * Get the filename associated with this reader. + * + * @return string + */ + public function getFilename() + { + return $this->_filename; + } + + /** + * Set the filename which is to be read. + * + * @param string $value The desired file handle. + * @return Zend_Gdata_App_MediaFileSource Provides a fluent interface. + */ + public function setFilename($value) + { + $this->_filename = $value; + return $this; + } + + /** + * The content type for the file attached (example image/png) + * + * @return string The content type + */ + public function getContentType() + { + return $this->_contentType; + } + + /** + * Set the content type for the file attached (example image/png) + * + * @param string $value The content type + * @return Zend_Gdata_App_MediaFileSource Provides a fluent interface + */ + public function setContentType($value) + { + $this->_contentType = $value; + return $this; + } + + /** + * Alias for getFilename(). + * + * @return string + */ + public function __toString() + { + return $this->getFilename(); + } + +} -- cgit v1.2.3