Exemple #1
0
 /**
  * Read from the stream
  *
  * http://bugs.php.net/21641 - stream_read() is always passed PHP's
  * internal read buffer size (8192) no matter what is passed as $count
  * parameter to fread().
  *
  * @param  integer $count
  * @return string
  */
 public function stream_read($count)
 {
     if (!$this->_objectName) {
         return false;
     }
     // make sure that count doesn't exceed object size
     if ($count + $this->_position > $this->_objectSize) {
         $count = $this->_objectSize - $this->_position;
     }
     $range_start = $this->_position;
     $range_end = $this->_position + $count - 1;
     // Only fetch more data from S3 if we haven't fetched any data yet (postion=0)
     // OR, the range end position plus 1 is greater than the size of the current
     // object buffer
     if ($this->_objectBuffer === null || $range_end >= strlen($this->_objectBuffer)) {
         $headers = array('Range' => "bytes={$range_start}-{$range_end}");
         $response = $this->_s3->_makeRequest('GET', $this->_objectName, null, $headers);
         if ($response->getStatus() == 206) {
             // 206 Partial Content
             $this->_objectBuffer .= $response->getBody();
         }
     }
     $data = substr($this->_objectBuffer, $this->_position, $count);
     $this->_position += strlen($data);
     return $data;
 }
Exemple #2
0
    /**
     * Read from the stream
     *
     * http://bugs.php.net/21641 - stream_read() is always passed PHP's 
     * internal read buffer size (8192) no matter what is passed as $count 
     * parameter to fread(). 
     *
     * @param  integer $count
     * @return string
     */
    public function stream_read($count)
    {
        if (!$this->_objectName) {
            return false;
        }

        // make sure that count doesn't exceed object size
        if ($count + $this->_position > $this->_objectSize) {
            $count = $this->_objectSize - $this->_position;
        }

        $range_start = $this->_position;
        $range_end = $this->_position+$count;

        // Only fetch more data from S3 if we haven't fetched any data yet (postion=0)
        // OR, the range end position is greater than the size of the current object
        // buffer AND if the range end position is less than or equal to the object's
        // size returned by S3
        if (($this->_position == 0) || (($range_end > strlen($this->_objectBuffer)) && ($range_end <= $this->_objectSize))) {

            $headers = array(
                'Range' => "bytes=$range_start-$range_end"
            );

            $response = $this->_s3->_makeRequest('GET', $this->_objectName, null, $headers);

            if ($response->getStatus() == 206) { // 206 Partial Content
                $this->_objectBuffer .= $response->getBody();
            }
        }

        $data = substr($this->_objectBuffer, $this->_position, $count);
        $this->_position += strlen($data);
        return $data;
    }
 /**
  *
  * @param <type> $method
  * @param <type> $path
  * @param <type> $params
  * @param <type> $headers
  * @param <type> $data
  * @return <type> 
  */
 public function _makeRequest($method, $path = '', $params = null, $headers = array(), $data = null)
 {
     if ('PUT' == $method && $this->defaultAcl) {
         $headers = array_merge(array(self::S3_ACL_HEADER => $this->defaultAcl), $headers);
     }
     return parent::_makeRequest($method, $path, $params, $headers, $data);
 }
Exemple #4
0
 /**
  * @see ZF-10219
  */
 public function testVersionBucket()
 {
     $this->_amazon->createBucket($this->_bucket);
     $response = $this->_amazon->_makeRequest('GET', $this->_bucket . '/?versions', array('versions' => ''));
     $this->assertNotNull($response, 'The response for the ?versions is empty');
     $xml = new SimpleXMLElement($response->getBody());
     $this->assertEquals((string) $xml->Name, $this->_bucket, 'The bucket name in XML response is not valid');
 }
Exemple #5
0
 /**
  * Read from the stream
  *
  * @param  integer $count
  * @return string
  */
 public function stream_read($count)
 {
     if (!$this->_objectName) {
         return false;
     }
     $range_start = $this->_position;
     $range_end = $this->_position + $count;
     // Only fetch more data from S3 if we haven't fetched any data yet (postion=0)
     // OR, the range end position is greater than the size of the current object
     // buffer AND if the range end position is less than or equal to the object's
     // size returned by S3
     if ($this->_position == 0 || $range_end > strlen($this->_objectBuffer) && $range_end <= $this->_objectSize) {
         $headers = array('Range' => "{$range_start}-{$range_end}");
         $response = $this->_s3->_makeRequest('GET', $this->_objectName, null, $headers);
         if ($response->getStatus() == 200) {
             $this->_objectBuffer .= $response->getBody();
         }
     }
     $data = substr($this->_objectBuffer, $this->_position, $count);
     $this->_position += strlen($data);
     return $data;
 }
Exemple #6
0
 public function setMeta($userInfo, $shareInfo, $metaData, $errorHandle = false)
 {
     $config = self::$_registry->get("config");
     if ($userInfo['id'] != $shareInfo['byUid']) {
         throw new Exception("User is not the owner of the share.");
     }
     $changeData = array();
     if ($errorHandle) {
         foreach (self::$_editableMetadata as $what) {
             if (empty($errorHandle[$what]) && $metaData[$what] != $shareInfo[$what]) {
                 $changeData[$what] = $metaData[$what];
             }
         }
     } else {
         $changeData = $metaData;
     }
     if (empty($changeData)) {
         return false;
     }
     if (isset($changeData['filename'])) {
         $s3 = new Zend_Service_Amazon_S3($config['services']['S3']['key'], $config['services']['S3']['secret']);
         $bucketPlusObjectKeyPrefix = $config['services']['S3']['sharesBucket'] . "/" . $userInfo['alias'] . "/" . $shareInfo['id'] . "-" . $shareInfo['download_secret'] . "/";
         $source = $bucketPlusObjectKeyPrefix . $shareInfo['filename'];
         $destination = $bucketPlusObjectKeyPrefix . $changeData['filename'];
         $meta = array(Zend_Service_Amazon_S3::S3_ACL_HEADER => Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ, "x-amz-copy-source" => $source, "x-amz-metadata-directive" => "COPY");
         $request = $s3->_makeRequest("PUT", $destination, null, $meta);
         if ($request->getStatus() == 200) {
             $filenameChanged = true;
         }
     }
     if (isset($filenameChanged) && $filenameChanged) {
         $removeFiles = Ml_Model_RemoveFiles::getInstance();
         $removeFiles->addFileGc(array("share" => $shareInfo['id'], "byUid" => $shareInfo['byUid'], "download_secret" => $shareInfo['download_secret'], "filename" => $shareInfo['filename'], "alias" => $userInfo['alias']));
         //Using delete from the S3 Zend class here doesn't work because of a bug
         //is not working for some reason after the _makeRequest or other things I tried to COPY...
     } else {
         unset($changeData['filename']);
     }
     if (empty($changeData)) {
         return false;
     }
     if (isset($changeData['description'])) {
         $purifier = Ml_Model_HtmlPurifier::getInstance();
         $changeData['description_filtered'] = $purifier->purify($changeData['description']);
     }
     $date = new Zend_Date();
     $changeData['lastChange'] = $date->get("yyyy-MM-dd HH:mm:ss");
     $this->_dbTable->update($changeData, $this->_dbAdapter->quoteInto("id = ?", $shareInfo['id']));
     return array_merge($shareInfo, $changeData);
 }