How do you work with temporary image uploads in PHP?

I am creating an online game in PHP where users can create game characters. Each character can have a portrait uploaded by the user. A player can have several characters at the same time, and images for them can be changed at any time. Naturally, photographs need to be resized and recompressed to avoid huge files. Here is my problem:

When a player changes his data (among them in the picture), and then clicks "save", the check on the server side is checked. It checks things like non-duplicate character names, empty required fields, etc. If any errors are found, they are displayed. In this case, the form must be pre-filled with the data entered by the player, so he should only change the bad bit, and not re-enter everything. But how do you save an image in this “temporary” state?

I can’t pre-fill the file upload field, browsers do not allow this. If I save it in a temporary file, then the image should be cleared at some point, because the player can simply close his browser and interrupt the whole process. When should it be? And what file name should I choose for a temporary file? If a player opens the same symbol for editing on two browser tabs, they should not conflict (each of them should have its own copy).

How would you solve this problem?

+3
source share
4 answers

, . . , . cron , (, ).

cron, , /. ( , , ), , , , .

+10

.

, , .. , .

. , , .

, , , _ - .

cron ( ).

0

, - , , . , , "modifing" , true. , false. , "" .

0

, , . , .

0
source

Source: https://habr.com/ru/post/1717750/


All Articles