tecnickcom/tc-lib-file
PHP utilities for low-level file access and byte-level reading. Provides local and remote file reads with host/path allowlists, big-endian binary byte readers, a prefixed temp-file cache, and typed exceptions. Part of the TCPDF ecosystem. Requires PHP 8.2+ with curl and pcre.
getByte/getUShort/getULong/getFixed with bounds-checked reads and \RangeException on overflow — a day of work you don't re-spend, and one you'd otherwise get wrong at the edge cases.File provides strict-deny allowedHosts/allowedPaths allowlists, per-hop redirect validation against the allowlist, CURLOPT_MAXREDIRS => 0 by default, and a maxRemoteSize cap measured on inflated bytes. That's a security-reviewed control you can point to in a threat model instead of writing yourself.allowedPaths with canonical/realpath() normalization, symlink-root handling (current -> releases/42), NUL-byte rejection, and per-volume case-sensitivity probing answers "can tenants escape their directory?" — a question that otherwise surfaces as a pentest finding.Cache gives prefixed, CSPRNG-suffixed temp files with scoped delete() semantics and deleteOlderThan(). Supports decisions like "cache rendered thumbnails for 24h" or "evict per-tenant" without inventing a naming convention that later deletes the wrong tenant's files.ext-intl) directly inform whether Windows Server or macOS-hosted deployments are in scope, or need a documented support boundary.Consider it when:
tc-lib-pdf ecosystem. This is a first-party component of a stack with 100M+ installs; adopting it is maintenance consolidation, not a new vendor.ext-curl, ext-pcre are already in your base image (they almost certainly are).Look elsewhere when:
Byte is an immutable reader over an in-memory string, and remote responses are buffered under a 50 MB default cap. Gigabyte media pipelines are the wrong fit.fopen + unpack() call in one place. The dependency isn't worth it for a single trivial read.For executives (30 seconds):
This is a small, mature utility from the team behind TCPDF — the PDF library with over 100 million installs. We need byte-level file reading and safe remote fetching for [feature]. Building it ourselves means re-implementing SSRF protection, path allowlisting, redirect validation, and size limits — exactly the class of code that produces security incidents when hand-rolled. Adopting it removes that risk and roughly [X] days of build plus ongoing security upkeep, at the cost of one dependency. The one item for legal is its LGPL-3.0 license, which is fine for our hosted model but needs a check if we ever ship on-prem binaries.
For engineering:
tecnickcom/tc-lib-file— PHP 8.2+,ext-curl+ext-pcre,ext-intloptional (enables NFC path folding on macOS). Five classes:File(local/remote reads behind host and path allowlists),Byte(bounds-checked big-endian reads, throws\RangeException),Cache(prefixed temp files, scoped deletes),Dir(writable parent lookup,open_basedir-aware),Exception.Defaults are strict-deny — empty
allowedHostsandallowedPathsmean everything is rejected until you configure them. Wire the allowlists from config, never from request input, and never use'*'. Redirects are off by default (CURLOPT_MAXREDIRS => 0); if you enable them, everyLocationtarget is re-checked against the allowlist. Remote responses are buffered and capped atmaxRemoteSize(50 MB default), counted post-inflation. The library reservesWRITEFUNCTION,PROGRESSFUNCTION,XFERINFOFUNCTION,NOPROGRESS, and (with redirects)HEADERFUNCTION— yoursetCurlOpts()values for those are replaced.Two API traps worth knowing up front:
isValidURL()/isValidFile()take arguments by reference and rewrite them — useisAllowedUrl()/isAllowedFile()for literals or expressions. AndCache::delete(null, $key)throws by design; a key requires its type.Scope boundaries to respect: 32-bit readers assume a 64-bit PHP build; Windows does not expand 8.3 short names, ADS, or trailing dots before allowlist matching; macOS Unicode folding is a no-op without
ext-intl. Document these if those platforms are in scope.Operational risk: 8 GitHub stars and no listed Packagist dependents. It's maintained as part of TCPDF, not as a standalone project. If it becomes load-bearing, plan to vendor or fork rather than depend on upstream responsiveness.
How can I help you explore Laravel packages today?