file upload forms
File Upload Forms: How to Build Them Safely
Learn how file upload forms work, how to add an upload field, set limits, keep files secure, and have your AI assistant build it on a full-stack platform.

A file upload form lets a visitor attach a document, photo or PDF and send it together with their answers. Adding the field is easy. Doing it safely is the hard part: size limits, allowed types, storage and access all need a decision. On WebsitePublisher, the AI web platform, your AI assistant builds and publishes websites and apps through the WebsitePublisher connector, and the full-stack backend (forms, uploads, data, email) is already built in. You describe the form in plain language. You do not wire up a server yourself.
TL;DR
- A file upload form is a normal form with one extra field. The file travels to a server and is stored with the submission.
- The browser can only hint at what is allowed. The server must enforce file type, size and count.
- Allow only the file types you need, rename files on arrival, and keep them away from public, executable locations.
- Decide who can open uploaded files and how long you keep them.
- With WebsitePublisher, your AI assistant (ChatGPT, Claude, Gemini, Grok and others) builds the form on a full-stack backend, and every change is live immediately.
Table of Contents
- What a file upload form does
- How to add a file upload field
- Set limits before you publish
- Keep uploads secure
- Where uploaded files go
- Why uploads fail, and how to fix them
- Build it with your AI assistant
- Questions to settle before you launch
- Our perspective
- Start your upload form
- FAQ
- Sources
What a file upload form does
A file upload form has a field where a visitor picks a file on their device and submits it with the other answers. The usual flow has five steps: the visitor selects the file, the form checks it against the field rules, the file moves to the server, the server stores it with the submission, and you or a downstream process open it later.

In plain HTML, the field is an input element with type="file". MDN’s reference for file inputs explains that it lets users select one or more local files, and the page can read each file’s name, size in bytes and MIME type. A MIME type is the label a file carries to say what kind it is, such as image/png. For privacy, the browser shows a fake path rather than the real folder on the visitor’s computer.
Common uses
- A freelancer collects a brief, a logo or reference images from a new client.
- A small business takes résumés for a job opening.
- A shop accepts a photo for a custom order.
- An agency gathers brand assets from clients before a launch.
- An app lets users attach a document to a support request or profile.
Each of these has a different risk. A résumé form holds personal data. A public image upload is open to abuse. Plan the field around the use, not the other way round.
How to add a file upload field
The manual route has four steps.
- Add the field. Use an
inputwithtype="file". Add theacceptattribute to guide the file picker, andmultipleif visitors may choose several files. - Set the form encoding. PHP’s manual on POST uploads says a working upload form needs the
POSTmethod andenctype="multipart/form-data"on theformtag. Without that encoding, the server receives the filename but not the file itself. - Receive the file on the server. Something on the backend must accept the upload, check it and store it. This is where most of the work and most of the risk sits.
- Connect it to the rest of your system. Link the file to the submission, notify yourself by email and make it visible in a place you can find.
Steps 3 and 4 are why a form with an upload field is harder than a plain contact form. A static page cannot do either. You need a backend.
That is the gap a full-stack platform closes. WebsitePublisher is full-stack: hosting, forms, email, uploads and data are part of the same backend that your site or app runs on. Your AI assistant builds the front-end form and connects it to that backend. You tell it what you want collected, and it assembles the pieces. Our AI web platform page shows how the assistants connect.
Set limits before you publish
Every upload field needs three limits: which file types it accepts, how large each file may be, and how many files one submission may contain.
| Limit | What to decide | Example for a client brief form |
|---|---|---|
| File types | Only formats you can use | PDF, DOCX, PNG, JPG |
| File size | Largest single file | Enough for a PDF or photo, not for video |
| File count | Files per submission | A handful, not unlimited |
Start from the task. If you only need a PDF résumé, do not accept images, archives or office macros. Keep executable files (programs and scripts) off the list entirely. Also check the server’s own upload ceiling. A field set higher than the host allows will fail for visitors with an unhelpful error.
Why the browser check is not enough
The accept attribute can list file extensions or MIME types. MDN is clear that it is only a hint for the file picker and that the server has to validate what actually arrives. A visitor can pick “All files” in the dialog, or send a request that never touches your form.
The same holds for size. PHP’s manual notes that the browser-side MAX_FILE_SIZE value is easy to bypass, while the server’s own size settings cannot be bypassed that way. Treat the browser rules as a courtesy to honest visitors and the server rules as the real gate.
Keep uploads secure
An upload field lets strangers put files on your server. That is the whole risk. The OWASP File Upload Cheat Sheet lists the threats: malware, parser exploits, storage-exhaustion attacks, overwriting existing files, and active content that harms other users who open it.
The same cheat sheet recommends a set of defenses. Use them as a checklist:
- Allowlist extensions. Accept a short list of known-good types. Do not try to block bad ones.
- Do not trust the declared type. The
Content-Typea request claims can be faked. Validate the file itself. - Generate new filenames. Replace the visitor’s filename with one your system creates. Filament’s documentation warns that keeping original filenames can leave an app open to remote code execution when files sit on a local or public disk.
- Cap the size. This also protects your storage from being filled up.
- Require authorization. Decide who may upload at all, and add CSRF protection so another site cannot submit uploads on a visitor’s behalf.
- Scan or sandbox the file where you can.
- Store files separately. Keep uploads away from the code that runs your site.
Microsoft’s ASP.NET Core upload guidance makes the storage point concrete: use a dedicated upload location, outside the app’s own directory tree, with execute permissions disabled. It also recommends generated safe filenames, approved extensions, server-side checks, size limits and malware scanning before storage.
Forms attract bots too. A public upload field with no protection invites junk files. Our guide on preventing form spam covers the layers that keep automated submissions out.
Security does not end at upload
Checks at the moment of upload are only the first layer. Files also need protection while they sit in storage and when someone retrieves them. Limit who can open them, serve them only to authorized people, and delete them when you no longer need them. A résumé you keep forever is a liability you chose.
Where uploaded files go
When a browser sends a file, the server first writes it to a temporary location. PHP’s manual says files land in the temporary directory, or the configured upload_tmp_dir, and are deleted at the end of the request unless your code moves or renames them. So the code must move the file somewhere permanent, or it vanishes.
Then you choose a home. Common options are the server’s own disk, or a separate object storage service with private visibility. Filament’s documentation shows a field configured for an S3 disk (a cloud storage bucket), a set directory and private visibility, and notes that deleting those files from the disk is the developer’s job. Deleting a submission does not always delete its files. Decide that rule up front.
A practical retention plan needs three rules:
- Say how long you keep files, for example until a project ends.
- Delete the file when you delete the record.
- Limit who can view files to the people who need them.
On WebsitePublisher, uploads and data sit in the same built-in backend as your forms, so a submission and its files live in one place instead of across a form tool, a storage account and an inbox.
Why uploads fail, and how to fix them
Most failures come from a short list of causes.
- Missing encoding. If the form lacks
multipart/form-data, the server gets a filename and no file. Add the encoding. - File too large. The visitor’s file exceeds the field limit or the server’s ceiling. Raise the limit to a sensible figure, or tell visitors the maximum next to the field.
- Wrong type. The visitor chose a format outside your allowlist. Show the allowed types beside the field, and return a clear error message.
- Canceled picker. MDN notes that a visitor can close the file dialog without choosing anything, so your code must handle an empty selection.
- Browser-only validation. Your rules pass in the browser but the server rejects or accepts differently. Make the server the authority.
- Slow connections. Large files on mobile networks time out. Keep limits modest and show progress where possible.
A good error message names the problem and the fix: “That file is over the size limit. Please upload a PDF or image under the size shown beside the field.”
Build it with your AI assistant
You do not have to write the form, the receiving code or the storage setup. With WebsitePublisher, you connect your AI assistant using the WebsitePublisher connector. It runs over MCP, the Model Context Protocol, a standard way for AI assistants to use outside tools. Through it, ChatGPT, Claude, Gemini, Grok and other assistants build and publish websites and apps for you. See the full list on our supported AI platforms page.
Because the backend is built in, your assistant does not generate untested server code for forms, uploads, email and data. It works with the platform’s backend and its 140+ tested integrations. Every change is live immediately. There is no separate deploy step, so you can edit the form and see the result at once.
A prompt that works
Be specific about the field, the limits and the follow-up. For example:
Add a project brief form to my site. Fields: name, email, project description and a file upload. Accept PDF, DOCX, PNG and JPG only, up to five files per submission. Email me when someone submits, and save each submission with its files.
Then review the result and adjust: tighten the types, set a per-file size limit, add a note beside the field. Because project memory and task history carry across sessions and assistants, you can come back later, or switch assistants, without explaining the project again.
If you also collect email addresses, our guide to email capture forms walks through wiring them up. If you already use an outside form service, see Typeform website integration for connecting it with webhooks.

Questions to settle before you launch
Answer these before the form goes live:
- What do I actually need? Name the file types and the reason for each.
- How big is too big? Set a per-file size and a file count.
- Who can upload? Anyone, or only signed-in users or invited clients?
- Who can open files? Limit access to the people who need it.
- How long do I keep them? Set a retention rule and follow it.
- What personal data is inside? Résumés, IDs and medical documents deserve extra care. If a form collects sensitive documents, check the privacy rules that apply to your business and your region.
- How will I know it works? Submit a test upload yourself, with an allowed file and a disallowed one, and read the messages a visitor would see.
Write the answers into your prompt. The clearer the brief, the closer the first version will be.
Our perspective
Most upload problems come from treating the field as a front-end detail. The field is the easy part. What matters is what happens on the server after the click: checks, naming, storage, access and deletion.
That is why we built WebsitePublisher as a full-stack AI web platform for websites and apps. Forms, uploads, email and data live in one backend, so your AI assistant is not inventing glue code each time you ask for a form. It snaps together tested pieces, and 140+ integrations cover the rest.
The second reason is speed of change. Every edit is live immediately, so tightening a file type or adding a field takes one conversation, not a release cycle. And because project memory stays across sessions and assistants, the form you described last month is still understood today.
Start your upload form
If you want a form with file uploads on a real backend, start on WebsitePublisher. Connect your AI assistant, describe the form, and review it as it goes live. The platform covers websites and apps, so the same backend can grow from a simple brief form into a client portal or a store. See the plans on our pricing page to pick the one that fits.

If you want to see how it all fits together first, our AI web platform with a real backend page explains the approach.
FAQ
What is considered a file upload?
A file upload is any case where a visitor selects a file on their device and sends it to a server through a form or app. The file can be a document, image, spreadsheet or archive. It travels with the other form answers and is stored on the server.
Is the accept attribute enough to secure uploads?
No. The accept attribute only guides the file picker in the browser. MDN says the server must still validate what arrives. Enforce an extension allowlist, size limits and file checks on the server side.
Why does my upload form send the filename but not the file?
The form is most likely missing enctype="multipart/form-data" and the POST method. PHP’s manual says both are required for a working upload form. Add them to the form tag and test again.
Can my AI assistant add a file upload to my site?
Yes. With WebsitePublisher, your AI assistant (ChatGPT, Claude, Gemini, Grok and others) builds and publishes websites and apps through the WebsitePublisher connector. Describe the form, the allowed file types and what should happen after submission. The change is live as soon as it is made.
Sources
- MDN: input type=“file”
- PHP Manual: POST method uploads
- OWASP File Upload Cheat Sheet
- Microsoft Learn: Upload files in ASP.NET Core
- Filament documentation: File upload
Recommended
Build your site the same way
Describe what you want. Your AI builds and publishes it — with the full stack behind it: data, auth, forms, payments, integrations and hosting.
See how it works →
Website