src/HTTP/Request2.php
protected function fopenWrapper($file, $detectType = false)
    {
        if (!is_string($file) && !is_resource($file)) {
            throw new HTTP_Request2_LogicException(
                "Filename or file pointer resource expected",
                HTTP_Request2_Exception::INVALID_ARGUMENT
            );
        }
        $fileData = array(
            'fp'   => is_string($file)? null: $file,
            'type' => 'application/octet-stream',
            'size' => 0
        );
        if (is_string($file)) {
            if (!($fileData['fp'] = @fopen($file, 'rb'))) {
                $error = error_get_last();
                throw new HTTP_Request2_LogicException(
                    $error['message'], HTTP_Request2_Exception::READ_ERROR
                );
            }
            if ($detectType) {
                $fileData['type'] = self::detectMimeType($file);
            }
        }
        if (!($stat = fstat($fileData['fp']))) {
            throw new HTTP_Request2_LogicException(
                "fstat() call failed", HTTP_Request2_Exception::READ_ERROR
            );
        }
        $fileData['size'] = $stat['size'];

        return $fileData;
    }
protected function fopenWrapper($file, $detectType = false)
    {
        if (!is_string($file) && !is_resource($file)) {
            throw new HTTP_Request2_LogicException(
                "Filename or file pointer resource expected",
                HTTP_Request2_Exception::INVALID_ARGUMENT
            );
        }
        $fileData = array(
            'fp'   => is_string($file)? null: $file,
            'type' => 'application/octet-stream',
            'size' => 0
        );
        if (is_string($file)) {
            if (!($fileData['fp'] = @fopen($file, 'rb'))) {
                $error = error_get_last();
                throw new HTTP_Request2_LogicException(
                    $error['message'], HTTP_Request2_Exception::READ_ERROR
                );
            }
            if ($detectType) {
                $fileData['type'] = self::detectMimeType($file);
            }
        }
        if (!($stat = fstat($fileData['fp']))) {
            throw new HTTP_Request2_LogicException(
                "fstat() call failed", HTTP_Request2_Exception::READ_ERROR
            );
        }
        $fileData['size'] = $stat['size'];

        return $fileData;
    }
Wrapper around fopen()/fstat() used by setBody() and addUpload()

@param string|resource $file       file name or pointer to open file
@param bool            $detectType whether to try autodetecting MIME
type of file, will only work if $file is a
filename, not pointer

@return array array('fp' => file pointer, 'size' => file size, 'type' => MIME type)
@throws HTTP_Request2_LogicException