File

class File extends UploadedFile (View source)

Traits

FileHelpers
Macroable

Properties

protected string $hashName The cache copy of the file's hash name. from FileHelpers
static protected array $macros The registered string macros. from Macroable
string $name The name of the file.
resource $tempFile The temporary file resource.
int $sizeToReport The "size" to report.
string|null $mimeTypeToReport The MIME type to report.

Methods

string path()

Get the fully qualified path to the file.

from FileHelpers
string extension()

Get the file's extension.

from FileHelpers
string hashName(string|null $path = null)

Get a filename for the file.

from FileHelpers
static void macro(string $name, object|callable $macro)

Register a custom macro.

from Macroable
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

from Macroable
static bool hasMacro(string $name)

Checks if macro is registered.

from Macroable
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

from Macroable
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

from Macroable
static FileFactory fake()

Begin creating a new file fake.

from UploadedFile
string|false store(string $path, array|string $options = [])

Store the uploaded file on a filesystem disk.

from UploadedFile
string|false storePublicly(string $path, array|string $options = [])

Store the uploaded file on a filesystem disk with public visibility.

from UploadedFile
string|false storePubliclyAs(string $path, string $name, array|string $options = [])

Store the uploaded file on a filesystem disk with public visibility.

from UploadedFile
string|false storeAs(string $path, string $name, array|string $options = [])

Store the uploaded file on a filesystem disk.

from UploadedFile
bool|string get()

Get the contents of the uploaded file.

from UploadedFile
string clientExtension()

Get the file's extension supplied by the client.

from UploadedFile
static UploadedFile createFromBase(UploadedFile $file, bool $test = false)

Create a new file instance from a base instance.

from UploadedFile
array parseOptions(array|string $options)

Parse and format the given options.

from UploadedFile
void __construct(string $name, resource $tempFile)

Create a new file instance.

static File create(string $name, string|int $kilobytes = 0)

Create a new fake file.

static File createWithContent(string $name, string $content)

Create a new fake file with content.

static File image(string $name, int $width = 10, int $height = 10)

Create a new fake image.

$this size(int $kilobytes)

Set the "size" of the file in kilobytes.

int getSize()

Get the size of the file.

$this mimeType(string $mimeType)

Set the "MIME type" for the file.

string getMimeType()

Get the MIME type of the file.

string tempFilePath()

Get the path to the temporary file.

Details

string path()

Get the fully qualified path to the file.

Return Value

string

string extension()

Get the file's extension.

Return Value

string

string hashName(string|null $path = null)

Get a filename for the file.

Parameters

string|null $path

Return Value

string

static void macro(string $name, object|callable $macro)

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

static FileFactory fake()

Begin creating a new file fake.

Return Value

FileFactory

string|false store(string $path, array|string $options = [])

Store the uploaded file on a filesystem disk.

Parameters

string $path
array|string $options

Return Value

string|false

string|false storePublicly(string $path, array|string $options = [])

Store the uploaded file on a filesystem disk with public visibility.

Parameters

string $path
array|string $options

Return Value

string|false

string|false storePubliclyAs(string $path, string $name, array|string $options = [])

Store the uploaded file on a filesystem disk with public visibility.

Parameters

string $path
string $name
array|string $options

Return Value

string|false

string|false storeAs(string $path, string $name, array|string $options = [])

Store the uploaded file on a filesystem disk.

Parameters

string $path
string $name
array|string $options

Return Value

string|false

bool|string get()

Get the contents of the uploaded file.

Return Value

bool|string

Exceptions

FileNotFoundException

string clientExtension()

Get the file's extension supplied by the client.

Return Value

string

static UploadedFile createFromBase(UploadedFile $file, bool $test = false)

Create a new file instance from a base instance.

Parameters

UploadedFile $file
bool $test

Return Value

UploadedFile

protected array parseOptions(array|string $options)

Parse and format the given options.

Parameters

array|string $options

Return Value

array

void __construct(string $name, resource $tempFile)

Create a new file instance.

Parameters

string $name
resource $tempFile

Return Value

void

static File create(string $name, string|int $kilobytes = 0)

Create a new fake file.

Parameters

string $name
string|int $kilobytes

Return Value

File

static File createWithContent(string $name, string $content)

Create a new fake file with content.

Parameters

string $name
string $content

Return Value

File

static File image(string $name, int $width = 10, int $height = 10)

Create a new fake image.

Parameters

string $name
int $width
int $height

Return Value

File

$this size(int $kilobytes)

Set the "size" of the file in kilobytes.

Parameters

int $kilobytes

Return Value

$this

int getSize()

Get the size of the file.

Return Value

int

$this mimeType(string $mimeType)

Set the "MIME type" for the file.

Parameters

string $mimeType

Return Value

$this

string getMimeType()

Get the MIME type of the file.

Return Value

string

protected string tempFilePath()

Get the path to the temporary file.

Return Value

string

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/7.x/Illuminate/Http/Testing/File.html