File Uploads in Laravel

Simple example: File from Form Request - Manage Filename, Extension, Folders


really great explanation , i read the documentation many times but i did not understand this topic well thank you


Just signed up. Thanks for the free weekend! It resulted in a new customer!

Instead of saving to the filesystem or to AWS, is there (or can you add) an example of using the User model / Controller to upload the image/file/binary to a blob (longblog, etc) field in the db (without necessarily getting into the argument of best practice of storing these in dbs, but maybe add a discussion of best practice of this)?

👍 1

Personally, I don't remember storing files in the DB ever. While it is possible, it's inconvenient if someone wants to access those files directly like in a "File explorer" window, quickly check the size of the folder, etc.

To me, personally, a file is a file, not a DB field.

So not sure if I want to create content around something that I personally haven't used ever.



Thanks for the reply! Enjoying the site and courese.

I understand if you don't want to create content for things that you don't use.

I actually store PDF (or other images) in some projects in a document model that belongsTo an account model. The document model includes the file date, size, type, provided name, and category, along with the document itself which is stored in a longblob column of the document table.

In the account view, I will display a table with the document information, sorted by date (or by other info like size or type) so the user can view all the documents attached to the account. The user can view them by simply clicking the id of the document which opens the PDF in a new tab.

Reasons I've found for doing this is ease of regular backups (backing up the database which also backups the PDFs as well), being able to sort the documents by category (or other column) within an account view, avoid issues when files move around or document names change (although this can be prevented, as well, but I've seen a disaster once before when all the files got corrupted, another time a colleague explained about a time when a manager decided to reorganize directories and moved all the files around creating havoc), oh, and speed. Clicking a document id to open the PDF in a new tab seems extremely fast (as opposed to pulling the document(s) from a file system, although I've not tested any metrics with this).

Seems there may be many use cases for this like doctors' offices with patients (patient records), lawfirms with clients (pleadings, motions, etc), personal inventory apps like car maintenance (receipts from mechanic showing work performed and price) to name a few.

Again, not getting into best practice, but this seems to work for me for small projects. I just don't see many examples of people doing it and thought it would be good to see an expert's opinion! I have document tables that exceed 50GB with 30,000 documents, and it's still lightening fast.

Again, thank you for the site, I'm learning quite a bit with laravel.