Answer the question
In order to leave comments, you need to log in
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
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
DELETE FROM table_name WHERE keep_until < now()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question