StickMemo.php 881 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. $memodir = "Memo/";
  3. if(isset($_POST['content']) !== False){
  4. $content = $_POST['content'];
  5. $content = bin2hex($content);
  6. }
  7. $max = 0;
  8. foreach (new DirectoryIterator('Memo/') as $fileInfo) {
  9. if ($fileInfo->isDot()) continue;
  10. $current = pathinfo($fileInfo->getFilename())['filename'];
  11. if (!is_numeric($current)) continue;
  12. if ($current > $max) $max = $current;
  13. }
  14. //Check if the number of files exceed the max
  15. if ($max > 1000){
  16. foreach (new DirectoryIterator('Memo/') as $fileInfo) {
  17. $current = pathinfo($fileInfo->getFilename())['filename'];
  18. if (!is_numeric($current)) continue;
  19. if ((int)$current != 0){
  20. unlink('Memo/' . $current . ".txt");
  21. }
  22. }
  23. $max = 0;
  24. }
  25. $filename = (int)$max + 1;
  26. $myfile = fopen($memodir . $filename . ".txt", "w") or die("Unable to open file!");
  27. $txt = $content;
  28. fwrite($myfile, $txt);
  29. fclose($myfile);
  30. echo $filename;
  31. ?>