I
I
Ilya Malinovsky2019-05-07 10:51:13
Laravel
Ilya Malinovsky, 2019-05-07 10:51:13

How to temporarily save an image in Laravel?

There is a task, you need to make a preview of a large picture (6000x3000) that the user loads through the form. Only the preview will be on another page of the site. This image needs to be saved somehow.
Is there a way in laravel to save a picture for a certain amount of time? So that the directory itself is then cleaned with temporary images. Or is there still a way to load the image as usual and clean up the directory by cron?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
JhaoDa, 2019-05-07
@iliya936

Is there a way in laravel to save a picture for a certain amount of time? So that the directory itself is then cleaned with temporary images.

cache .

E
Eugene Wolf, 2019-05-07
@Wolfnsex

Is there a way in laravel to save a picture for a certain amount of time?
In Laravel itself - hardly (most likely - not). Due to the fact that this is not a very typical task and it has no direct relation to a specific framework (for example, Laravel).
Or is there still a way to load the image as usual and clean up the directory by cron?
I would use at , it seems to me a little more suitable for this task.
Also, Redis has the ability to set the data lifetime, and Laravel has support for Redis. You can take advantage of this Redis feature by storing data there. Also in Redis there are " events " that, incl. can notify that the lifetime of "such and such" data has expired and bind accordingly. deleting the file associated with this data from the disk.
*both of these options, in theory, may fail and the data may not be deleted, for this reason, once every N hours / days, I would still recommend scanning the directory with files for "undeleted garbage".
MySQL has a built-in scheduler, files can be saved there and deleted after their expiration date (which can be specified when saving).
If necessary, you can "drag heavy artillery", install a queue server (or use an existing one, if there is one, something was written about it here ), respectively. when uploading a picture, add a task to delete it as "deferred".
PS "Which is better" - depends on each case individually, if there is nothing "extra" in the project - you can use at + cron (for infrequent checks for the presence of various garbage, which for some reason was not deleted, although it is possible and not necessarily, I did not conduct deep tests ...)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question