HttpFile
Raxos\Http\HttpFile
Represents a single uploaded file. Each instance wraps one entry of the PHP $_FILES superglobal, so a form field that uploads several files results in one HttpFile per file. The object is immutable and implements the contract DebuggableInterface.
final readonly class HttpFile implements DebuggableInterfaceConstructor
public function __construct(private array $file)Takes one raw $_FILES entry (the array with the error, type, name, size and tmp_name keys) and derives the public properties from it. You rarely call this yourself: HttpFilesMap builds the instances through its createFromGlobals() factory and exposes them on HttpRequest::$files.
Properties
All properties are public and readonly.
public bool $isValid;
public string $contentType;
public string $name;
public int $size;
public string $temporaryFile;isValidistrueonly when the underlying PHP upload error code wasUPLOAD_ERR_OK. A failed or missing upload yieldsfalse.contentTypeis the MIME type reported by the client ($file['type']).nameis the original client filename ($file['name']).sizeis the file size in bytes ($file['size']).temporaryFileis the path to the temporary upload on disk ($file['tmp_name']), which you move to permanent storage.
Debug view
public function __debugInfo(): arrayReturns a content_type, name, size and temporary_file view for var_dump() and debuggers. The raw $file array is intentionally excluded.
Example
<?php
declare(strict_types=1);
use Raxos\Http\HttpRequest;
$request = HttpRequest::createFromGlobals();
foreach ($request->files->get('avatar') ?? [] as $file) {
if (!$file->isValid) {
continue;
}
// $file->name, $file->contentType, $file->size
move_uploaded_file($file->temporaryFile, "/storage/{$file->name}");
}Validation
The Upload constraint attribute checks a mapped property against this type. It rejects a value that is not an HttpFile or whose isValid is false, and returns the HttpFile otherwise:
use Raxos\Contract\Http\HttpRequestModelInterface;
use Raxos\Http\HttpFile;
use Raxos\Http\Validate\Attribute\Property;
use Raxos\Http\Validate\Constraint\Upload;
final class UploadAvatarRequest implements HttpRequestModelInterface
{
public function __construct(
#[Property]
#[Upload]
public HttpFile $avatar
) {}
}