PHP Deleting a file 24 hours after being uploaded
Posted
by
user3742063
on Stack Overflow
See other posts from Stack Overflow
or by user3742063
Published on 2014-08-23T16:06:18Z
Indexed on
2014/08/23
16:20 UTC
Read the original article
Hit count: 121
I've made a simple script that allows users to upload html files to a web directory on my server. However, I'd like it so each file is deleted after 24 hours of being on my server. 24 hours for each file, not 24 hours for the entire directory. Here is my code so far... Thank you for your help. :)
<?php
$target = "users/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)
&& ($_FILES["uploaded"]["type"] == "html"))
{
echo "File: " . $_FILES["uploaded"]["name"] . "<br />";
echo "Type: " . $_FILES["uploaded"]["type"] . "<br />";
echo "Size: " . ($_FILES["uploaded"]["size"] / 1024) . " Kb<br />";
echo "Location: /users/" . $_FILES["uploaded"]["name"];
}
else {
echo "Sorry, " . $_FILES["uploaded"]["name"] . " is not a valid HTML document. Please try again.";
unlink . $_FILES["uploaded"]["name"];
}
?>
© Stack Overflow or respective owner