ZF-11435: Zend_Http_Client method setRawData - fstat fails on remove file pointers

Description

public function setRawData($data, $enctype = null) { $this->raw_post_data = $data; $this->setEncType($enctype); if (is_resource($data)) { // We've got stream data $stat = @fstat($data); if($stat) { $this->setHeaders(self::CONTENT_LENGTH, $stat['size']); } } return $this; }

When passing in a file pointer to a remote file via Zend_Service_Amazon_S3 putFileStream method the fstat fails in the above method causing a content length required error from amazon. Maybe a method this this should be used instead:

/** * Return the size in bytes of a local or remote file * * @param string $file - path to file * @return int */ public static function getFileSize($path) { if(substr($path,0,4) != 'http') return @filesize($path);

    $x = array_change_key_case(get_headers($path, 1),CASE_LOWER); 

    $length = null;

    if(is_array($x['content-length']))
        $length = $x['content-length'][count($x['content-length']) - 1];
    else
        $length = $x['content-length'];

    if(empty($length))
        $length = @filesize($path); 

    return (int) $length;   
}

Comments

No comments to display