0

If I were to create a board like 4Chan. How could I make it so a post that would expire and be perm. deleted after 24 hours?

Here is what I have so far for saving the file:

    <?php
$allowedExts = array("gif", "jpeg", "jpg", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br>";
    echo "Type: " . $_FILES["file"]["type"] . "<br>";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>

All help is appreciated!

Menelaos
  • 23,508
  • 18
  • 90
  • 155
woods
  • 11
  • 2
    What you "have so far" is just copy and pasted code, not pretty good code mind you. You need to think about your actual goal (uploaded images != posts), and google a bit further. – mario May 26 '13 at 22:51
  • Do you have a database to store information about the posts? – Barmar May 26 '13 at 22:51

1 Answers1

1

Based on the code you have added, I suspect you are looking for a file based approach.

Nevertheless, as stated in the comments, it would also be good to have a database such as MYSQL to store your data.

Additionally, in your tags and question you don't specify important information such as: on which operating system.

Neverthess less, based on your code that your creating files, here are resources related to deleting files created after X amount of time:

And also related to scheduled tasks and cron:

Community
  • 1
  • 1
Menelaos
  • 23,508
  • 18
  • 90
  • 155