source: extensions/Google2Piwigo/include/Zend/Gdata/App/MediaFileSource.php @ 17475

Last change on this file since 17475 was 17475, checked in by mistic100, 12 years ago

new extension: Google2Piwigo

File size: 3.9 KB
RevLine 
[17475]1<?php
2
3/**
4 * Zend Framework
5 *
6 * LICENSE
7 *
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.
15 *
16 * @category   Zend
17 * @package    Zend_Gdata
18 * @subpackage App
19 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license    http://framework.zend.com/license/new-bsd     New BSD License
21 * @version    $Id: MediaFileSource.php 24594 2012-01-05 21:27:01Z matthew $
22 */
23
24/**
25 * @see Zend_Gdata_App_MediaData
26 */
27require_once 'Zend/Gdata/App/BaseMediaSource.php';
28
29/**
30 * Concrete class to use a file handle as an attachment within a MediaEntry.
31 *
32 * @category   Zend
33 * @package    Zend_Gdata
34 * @subpackage App
35 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
36 * @license    http://framework.zend.com/license/new-bsd     New BSD License
37 */
38class Zend_Gdata_App_MediaFileSource extends Zend_Gdata_App_BaseMediaSource
39{
40    /**
41     * The filename which is represented
42     *
43     * @var string
44     */
45    protected $_filename = null;
46
47    /**
48     * The content type for the file attached (example image/png)
49     *
50     * @var string
51     */
52    protected $_contentType = null;
53
54    /**
55     * Create a new Zend_Gdata_App_MediaFileSource object.
56     *
57     * @param string $filename The name of the file to read from.
58     */
59    public function __construct($filename)
60    {
61        $this->setFilename($filename);
62    }
63
64    /**
65     * Return the MIME multipart representation of this MediaEntry.
66     *
67     * @return string
68     * @throws Zend_Gdata_App_IOException
69     */
70    public function encode()
71    {
72        if ($this->getFilename() !== null &&
73            is_readable($this->getFilename())) {
74
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.');
82            }
83            fclose($fileHandle);
84            return $result;
85        } else {
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.');
89        }
90    }
91
92    /**
93     * Get the filename associated with this reader.
94     *
95     * @return string
96     */
97    public function getFilename()
98    {
99        return $this->_filename;
100    }
101
102    /**
103     * Set the filename which is to be read.
104     *
105     * @param string $value The desired file handle.
106     * @return Zend_Gdata_App_MediaFileSource Provides a fluent interface.
107     */
108    public function setFilename($value)
109    {
110        $this->_filename = $value;
111        return $this;
112    }
113
114    /**
115     * The content type for the file attached (example image/png)
116     *
117     * @return string The content type
118     */
119    public function getContentType()
120    {
121        return $this->_contentType;
122    }
123
124    /**
125     * Set the content type for the file attached (example image/png)
126     *
127     * @param string $value The content type
128     * @return Zend_Gdata_App_MediaFileSource Provides a fluent interface
129     */
130    public function setContentType($value)
131    {
132        $this->_contentType = $value;
133        return $this;
134    }
135
136    /**
137     * Alias for getFilename().
138     *
139     * @return string
140     */
141    public function __toString()
142    {
143        return $this->getFilename();
144    }
145
146}
Note: See TracBrowser for help on using the repository browser.