icom/ framework

ໄຟລ໌ສ່ວນຕົວ ແລະ upload ທີ່ຈຳກັດ.

ເກັບໄຟລ໌ນອກ document root, ກຳນົດຂະໜາດ/ຊະນິດ ແລະກວດສິດກ່ອນດາວໂຫຼດ.

1. ຕຽມ private directory

LocalStorage ໃຊ້ directory ທີ່ມີຢູ່ແລ້ວ, canonical absolute path, mode 0700 ແລະບໍ່ມີ symlink ໃນ path. ຕ້ອງເປັນ local POSIX filesystem ທີ່ຮອງຮັບ hard link; operator ຕ້ອງຄວບຄຸມ directory ແລະ parents. ຢ່າວາງໄວ້ໃນ public/. ບໍ່ໃຊ້ client filename ເປັນ filesystem path.

example
install -d -m 700 /private/application-files
# Use your actual private path and application OS user.

2. ຂຽນ stream ແບບມີຂອບເຂດ

put ສ້າງ immutable object ID 64 hexadecimal characters, ຂຽນໄຟລ໌ mode0600 ແລະ publish ແບບບໍ່ overwrite. ຖ້າເກີນ limit ຫຼື stream ບໍ່ສົມບູນ ຈະລົ້ມເຫຼວແລະລຶບ staging file. JSON metadata ມີ id, bytes, media_type, sha256; ບໍ່ມີ private path.

example
use Icom\Storage\LocalStorage;
use Nyholm\Psr7\Stream;

$files = new LocalStorage('/private/application-files', maxBytes: 2_000_000);
$saved = $files->put(Stream::create('Generated report'));
// Persist $saved->id with the owning account/tenant in your database.
// Authorize the current account and resource before reading or deleting.
$response = $files->download($saved->id, 'report.txt');

3. ຮັບ upload ແບບ opt-in

RequestGuard ປະຕິເສດ multipart ໂດຍຄ່າເລີ່ມຕົ້ນ. ແກ້ registration ຂອງ guard ທີ່ມີຢູ່ໃນ bootstrap ໃຫ້ອະນຸຍາດ exact POST path; ການເພີ່ມ guard ອີກອັນຫຼັງ default guard ບໍ່ເປີດ upload. ຕ້ອງມີ bounded Content-Length ແລະ trusted SAPI/PSR multipart parser. ຕັ້ງ web-server/PHP post_max_size, upload_max_filesize, max_file_uploads ໃຫ້ສອດຄ່ອງ. ສົ່ງ CSRF token ຜ່ານ X-CSRF-Token; authentication/authorization ຍັງຈຳເປັນ.

example
use Icom\Middleware\RequestGuard;
use Icom\Storage\{UploadPolicy, Uploads};

$guard = new RequestGuard(['your-app.example'], 3_000_000, ['/account/files']);
$uploads = new Uploads($files);
$policy = new UploadPolicy(2_000_000, ['image/png', 'image/jpeg']);
// Inside an authenticated and authorized POST /account/files handler:
// $upload = $request->getUploadedFiles()['document'];
// $saved = $uploads->store($upload, $policy);

4. MIME ແລະການດາວໂຫຼດ

UploadPolicy ຕ້ອງມີ ext-fileinfo ແລະ allowlist ຊັດເຈນ; ຮອງຮັບ image/jpeg, image/png, application/pdf, text/plain. ກວດ bytes ຈິງ ແລະ PHP upload error; ບໍ່ເຊື່ອ client MIME/name. Fileinfo ບໍ່ແມ່ນ antivirus, image decoder ຫຼື polyglot detector. download ຕອບ attachment + application/octet-stream + nosniff + no-store. ບໍ່ເປີດ inline HTML/SVG; ກຳນົດ ASCII attachment name ສຳລັບສະແດງເທົ່ານັ້ນ.

5. ວົງຈອນໄຟລ໌

ID ທີ່ຄາດເດົາຍາກບໍ່ແມ່ນສິດເຂົ້າເຖິງ. ເກັບ mapping ກັບ owner/tenant, ກວດ policy ທຸກ read/delete/download, ກຳນົດ quota/retention/backup ແລະຈັດການ orphan ຫຼັງ DB failure. Filesystem ແລະ SQL ບໍ່ຢູ່ transaction ດຽວກັນ. ບໍ່ມີ encryption-at-rest, antivirus, cloud replication ຫຼື public upload endpoint ຖືກເປີດໃນເວັບເອກະສານ. Multipart integration ຕ້ອງທົດສອບແຍກຕາມ FPM/worker adapter.

PHP upload errors ↗

Developer preview — benchmark claims require reproducible evidence.

Explore the architecture