A defense-in-depth check for $_FILES uploads: confirms the upload completed, the size is within bounds, the MIME type matches an allow-list (by libmagic, not by extension), and the file landed where PHP expected.
Use PHP's built-in finfo (libmagic) to detect a file's true MIME type from its bytes — not from the extension, which can be lied about. Critical for validating user uploads.
Shrink an uploaded image so its longest side is no more than $maxDim pixels, preserving aspect ratio. Re-encodes to JPEG at the given quality. Uses the GD extension.
POST a file (or several) as multipart/form-data using requests, with optional extra form fields. Lets you upload to /avatar-style endpoints without manual boundary construction.