TelegramPHP Documentation

InputFile
in package
implements Stringable

FinalYes

A file to upload - the `InputFile` of the Bot API.

Pass one anywhere the spec accepts InputFile or String, at any depth, and the call switches itself to multipart/form-data:

$telegram->sendPhoto($chatId, InputFile::fromPath('cat.jpg'), caption: 'mine');

Sending a file_id or an HTTP URL needs none of this - pass the plain string.

Tags
link
https://core.telegram.org/bots/api#sending-files
author

Valithor Obsidion valithor@valgorithms.com

Table of Contents

Interfaces

Stringable

Properties

$contents  : ?string
$contentType  : ?string
$filename  : string
$path  : ?string

Methods

__toString()  : string
attachName()  : string
The `attach://` form a nested upload is referenced by.
fromPath()  : self
Reads the upload from disk when the request is encoded.
fromStream()  : self
Drains a stream resource into the upload.
fromString()  : self
Uploads bytes already in memory.
getContents()  : string
The bytes to send, read from disk on first use.
getContentType()  : ?string
The declared MIME type, guessed from the file when one was not given.
getFilename()  : string
getPath()  : ?string
__construct()  : mixed

Properties

$contents read-only

private ?string $contents

$contentType read-only

private ?string $contentType

$filename read-only

private string $filename

Methods

__toString()

public __toString() : string
Return values
string

attachName()

The `attach://` form a nested upload is referenced by.

public attachName() : string
Return values
string

fromPath()

Reads the upload from disk when the request is encoded.

public static fromPath(string $path[, ?string $filename = null ][, ?string $contentType = null ]) : self
Parameters
$path : string
$filename : ?string = null
$contentType : ?string = null
Tags
throws
FileNotFoundException

When the path is not a readable file.

Return values
self

fromStream()

Drains a stream resource into the upload.

public static fromStream(resource $stream, string $filename[, ?string $contentType = null ]) : self
Parameters
$stream : resource
$filename : string
$contentType : ?string = null
Return values
self

fromString()

Uploads bytes already in memory.

public static fromString(string $contents, string $filename[, ?string $contentType = null ]) : self
Parameters
$contents : string
$filename : string
$contentType : ?string = null
Return values
self

getContents()

The bytes to send, read from disk on first use.

public getContents() : string
Return values
string

getContentType()

The declared MIME type, guessed from the file when one was not given.

public getContentType() : ?string
Return values
?string

getFilename()

public getFilename() : string
Return values
string

getPath()

public getPath() : ?string
Return values
?string

__construct()

private __construct(?string $path, ?string $contents, string $filename, ?string $contentType) : mixed
Parameters
$path : ?string
$contents : ?string
$filename : string
$contentType : ?string
On this page

Search results