File
True\File handles file uploads from HTML forms. You access uploads through $request->files-><field>, check ->uploaded, then move() the file into place — with optional image resizing, format conversion, and cropping baked into the same pipeline.
Single file upload
When a form posts <input type="file" name="fieldName">, the upload appears at $request->files->fieldName:
if ($request->files->fieldName->uploaded) {
$request->files->fieldName->move(BP.'/assets/', $request->files->fieldName->name);
echo $request->files->fieldName->ext; // e.g. "jpg"
echo $request->files->fieldName->mime; // e.g. "image/jpeg"
}
Multiple file upload
When the input is an array (<input type="file" name="fieldName[]" multiple>), the property becomes a numerically indexed list:
echo $request->files->fieldName[0]->name;
echo $request->files->fieldName[1]->name;
Resizing an uploaded image
Set the image-processing properties before calling process(), then move() the result:
$request->files->file->imageWidth = 800;
$request->files->file->imageHeight = 800;
$request->files->file->imageQuality = 80;
try {
$request->files->file->process();
$request->files->file->move($path, $fileName);
$App->response('{"result":"success", "filename":"' . $fileName . '"}', 'json');
} catch (Exception $e) {
$App->response('{"result":"error", "error":"' . $e->getMessage() . '"}', 'json', 422);
}
Changing format and cropping
Set format to convert (jpg/png/webp/…), and crop to clip the result:
$request->files->file->format = 'jpg';
$request->files->file->imageWidth = 800;
$request->files->file->imageHeight = 800;
$request->files->file->imageQuality = 80;
// Explicit pixel crop: [top, right, bottom, left]
$request->files->file->crop = [0, 0, 20, 20];
// Or center-crop to a square
$request->files->file->crop = 'square';
// Crop a square from the bottom
$request->files->file->crop = 'bottomSquare';
// Crop a square from the top
$request->files->file->crop = 'topSquare';
$request->files->file->process();
$request->files->file->move($path, $fileName);
Properties
| Property | Purpose |
|---|---|
uploaded | Boolean — whether the field has a file in it. |
name | Original filename submitted with the upload. |
ext | File extension (no dot). |
mime | Detected MIME type. |
imageWidth / imageHeight | Target dimensions for process(). |
imageQuality | JPEG quality (1–100). Default 90. |
format | Target image format on conversion (jpg, png, …). |
crop | Array [t, r, b, l] or one of square / topSquare / bottomSquare. |
Methods
| Method | Purpose |
|---|---|
process(): void | Resize / convert / crop using the properties above. Throws on failure. |
move(string $path, string $filename): void | Move the (optionally processed) upload into $path with the given filename. Throws on failure. |