#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →

Uploading Files and Validating Uploads

File uploads — profile pictures, documents, attachments — are a common requirement in real applications, and Laravel provides a clean, consistent way to accept and validate them before anything gets saved.

Accepting a File Upload

A file input in an HTML form must include the enctype="multipart/form-data" attribute, or the file simply won't be sent. On the Laravel side, the uploaded file is accessible through the request object as an instance of Laravel's file class, which wraps helpful metadata like original name and size.

Validating Uploaded Files

Just like any other form input, uploaded files should be validated before being trusted or stored. Laravel includes several rules specifically for files, covering type, size, and even image dimensions.

RuleWhat It Checks
fileConfirms the input is a successfully uploaded file
imageRestricts the upload to common image formats
mimes:pdf,docxRestricts uploads to specific file extensions
max:2048Limits file size, specified in kilobytes
dimensions:min_width=100Enforces minimum or maximum image dimensions

Good Practices for Uploads

Once a file passes validation, it needs somewhere to actually live — which raises the question of where Laravel stores files, and the difference between its public and storage folders.

Ready to master Laravel Training Course?

Join Uncodemy's hands-on Laravel program and build real, production-ready applications.

Explore Course