S
S
Suleimanov_Ismar2015-11-26 05:20:23
PHP
Suleimanov_Ismar, 2015-11-26 05:20:23

How to make limited storage time?

Hello everyone.
There is a task, a limited storage time, the limit is chosen by the user.
For example: 2 inputs, in one we write a number and in the other we select the type of storage from the drop-down list
2 | hours (minutes, days, week)
I did the task with storage for several days and weeks.
but how to do 1 and 2? how to make storage for several hours/minutes?
this is how i did storing the days
where
$row_c['load_date'] is the file upload time.
$current_d - current time.
$row_c['time_save'] - user selected storage time.

$count_date = $row_c['load_date'] - $current_d;

        $difference = intval(abs(strtotime($row_c['load_date']) - strtotime($current_d))); 

        // Количество дней 
          $finish_c_d = (int)$int_count_date = $difference / (3600 * 24);
              
          // Проверка и удаление
          // Проверка дней
          if ($finish_c_d > $row_c['time_save']) {
            echo "время истекло, данные удалились! id= ".$row_c['id'];
          }else{echo "Рано удалять! id= ".$row_c['id'];}
          
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2015-11-26
@Suleimanov_Ismar

When saving data, specify the date after which the data should be deleted.

$keep_until = date("Y-m-d H:i:s", strtotime("+1 week"));
$query = "INSERT INTO table_name (data, keep_until) VALUES ('$user_data', '$keep_until')"; // да, лучше использовать PDO

Run a "garbage collector" at some interval, which will make a query like
DELETE FROM table_name WHERE keep_until < now()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question