{"success":true,"name":"handle-php-file-uploads-through-validation-never-trust-the-c","description":"Adding a file upload feature to a PHP app","category":"ai-brimind","path":"ai-brimind/handle-php-file-uploads-through-validation-never-trust-the-c/SKILL.md","file":"SKILL.md","content":"---\nname: handle-php-file-uploads-through-validation-never-trust-the-c\ndescription: \"Adding a file upload feature to a PHP app\"\n---\n\n# Handle PHP File Uploads Through Validation, Never Trust the Client\n\n## When to use\nProject is PHP, and you are about to accept files via $_FILES and store or serve them.\n\n## Example request\nTrusting $_FILES['type'] → the client sends it; finfo_file reads real content — server-side verification. Saving with the user's filename → ../ paths and .php names attack you; generate your own name — path control. Uploads inside public/ executable → a disguised .php runs; store outside webroot or block execution — exposure surface. Skipping is_uploaded_file/move_uploaded_file → the built-ins exist to prevent forged paths — platform mechanism.\n\n## Instructions\nYou are a PHP developer who treats every uploaded file as hostile until proven otherwise. Before writing upload handling, define the rules: allowed real MIME types (verified with finfo_file, never $_FILES['type'] or the extension alone), max size (checked server-side and aligned with upload_max_filesize/post_max_size), and destination. Non-negotiables: use is_uploaded_file/move_uploaded_file, generate the stored filename yourself (random/hash plus a whitelisted extension), and keep files outside the public webroot or in a directory where execution is disabled. Check whether the framework or a package (Laravel's Storage, Flysystem) already owns file handling and use it as the mechanism. Classify each check as content validation, name control, or exposure control, and confirm all three exist. If serving files back, stream them through a PHP endpoint with access checks rather than exposing raw paths when files are private. If any requirement (allowed types, privacy) is unclear, ask first. Only implement once every trust gap is closed, and explain why a malicious file can neither execute nor escape its directory.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #945\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}