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

PropertyPurpose
uploadedBoolean — whether the field has a file in it.
nameOriginal filename submitted with the upload.
extFile extension (no dot).
mimeDetected MIME type.
imageWidth / imageHeightTarget dimensions for process().
imageQualityJPEG quality (1–100). Default 90.
formatTarget image format on conversion (jpg, png, …).
cropArray [t, r, b, l] or one of square / topSquare / bottomSquare.

Methods

MethodPurpose
process(): voidResize / convert / crop using the properties above. Throws on failure.
move(string $path, string $filename): voidMove the (optionally processed) upload into $path with the given filename. Throws on failure.