Upload and structure for image storage in Laravel

Asked

Viewed 2,341 times

2

I started to build a portal, using Laravel, which has as requirements: users, sites belonging to users and classified belonging to users.

As each of these requirements requires images, I would like to know the best method to store images for each of these requirements and associated with them.

My doubt is more based on the folder structure to store the photos, and on the image upload system in Laravel.

2 answers

3

There are several things to look at:

  • Is your deploy made by any automated tool? e.g. Capistrano? If yes, the structure should be mounted outside the folder of your application (which is usually done in the public directory). You can also point the public directory to an external folder (via a symbolic link)
  • Will you write to any CDN/Cloud files? p.e. Amazon S3? In this case the structure is made by Buckets, so you will have to think a little differently.

The structure could be something like:

shared/usuarios/
shared/usuarios/places
shared/usuarios/classificados

In the case of option 1 would be folders, in option 2, Buckets.

About the uploading system is no secret, the uploading API is simple to use. I recommend saving the path of these directories in configuration files, so that it is easy for you to move in the future if you need to.

Below is the Docs link: http://laravel.com/docs/requests#files

  • In this case, the structure would not have to be: Shared/usuarios/usuario_id/classifieds ?

  • Yes, it can be, or else Shared/usuarios/classifieds/{usuario_id} so the user folder is more "clean". Ai is a matter of taste same

2

Use the package codesleeve/stapler

With it you will associate images to a record of the table you want to place an image.

In general I create a table only for images and link the record of this table to a record of other tables, so I can have more than one image linked to the record without difficulties.

One of the differentials of this package is the possibility to send your image to an Amazon S3 Bucket, which becomes a very good thing if you have to deal with many images.

  • Thanks, I did not know this form of storage for a Amazon S3 Bucket!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.