beam.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. include("lib.php");
  3. include("header.html");
  4. echo("\n<main class=\"text-center\">\n");
  5. function celebrate($dest_file)
  6. {
  7. ?>
  8. <p class="uppercase">Thank you for feeding me</p>
  9. <p class="uppercase">Your coin is in safe hands</p>
  10. <p class="uppercase">It will not be de-atomized for at least a year</p>
  11. <title>COIN INSERTED <3</title>
  12. <img alt="A coin lovingly inserted to a coin-slot" src=res/img/coininserted_big.png>
  13. <p class="uppercase">Your coin's <a href="<?php echo($dest_file); ?>">over here</a></p>
  14. <p class="uppercase"><a href="<?php echo($dest_file); ?>">
  15. https://coinsh.red/<?php echo($dest_file); ?></a></p>
  16. <p class="uppercase">It's meta-stuff (or lack thereof) is
  17. <a href="<?php echo($dest_file); ?>.txt">here</a></p>
  18. <?php
  19. }
  20. function celebrate_death($dest_file, $upload_method)
  21. {
  22. ?>
  23. <title>COIN ON FIRE</title>
  24. <img alt="Ouch, that coin's on fire. Literally." src="res/img/coinfire_big.png">
  25. <p>...</p>
  26. <p class="uppercase">That was weird, something went wrong.</p>
  27. <p class="uppercase">Give it another go-- if it happens again, tell me.<p>
  28. <p class="uppercase">Also tell this: "File: <?php echo($dest_file); ?>,
  29. Method: <?php echo($upload_method); ?>."</p>
  30. <?php
  31. }
  32. function check_name_length($file_name)
  33. {
  34. if (strlen($file_name) > 36)
  35. {
  36. ?>
  37. <p> just a friendly note:</p>
  38. <p>it looks like your filename is total gibberish or really long.</p>
  39. <p>it could probably be a bit prettier--<p>
  40. <p> remember, you can use the filename box when uploading to set a custom filename.</p>
  41. <?php
  42. }
  43. }
  44. if (!empty($_POST["upload_url"]))
  45. {
  46. $upload_url = $_POST["upload_url"];
  47. $file_name = url_to_filename($upload_url);
  48. $upload_method = 2;
  49. }
  50. else if (!empty($_POST["desired_filename"]))
  51. {
  52. $file_name = $_POST["desired_filename"];
  53. $upload_method = 1;
  54. }
  55. else if (!empty($_FILES["fileToUpload"]["name"]))
  56. {
  57. $file_name = $_FILES["fileToUpload"]["name"];
  58. $upload_method = 1;
  59. }
  60. else
  61. {
  62. $upload_method = 0;
  63. }
  64. // check if file-name has any... undesirable characteristics
  65. $file_name = sanitize_filename($file_name);
  66. // and now we pretend that never happened
  67. $dest_dir = "p/";
  68. $dest_file = $dest_dir . $file_name;
  69. $beaming_permitted = 1;
  70. if (file_exists($dest_file))
  71. {
  72. echo("\t<p class=\"uppercase\">We're getting some interference</p>\n");
  73. echo("\t<p class=\"uppercase\">Please use a different coin-name</p>\n\n");
  74. $beaming_permitted = 0;
  75. }
  76. if ($beaming_permitted == 0)
  77. {
  78. echo("\t<title>COIN ON FIRE</title>\n\n");
  79. echo("\t<img alt=\"A big coin in bloody flames.\" src=res/img/coinfire_big.png>\n");
  80. echo("\t<p>sorry <\\3</p>\n");
  81. }
  82. else
  83. {
  84. if ($upload_method == 1)
  85. {
  86. if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],$dest_file))
  87. {
  88. write_metadata($dest_file, $_POST["file_desc"], $_POST["file_source"]);
  89. celebrate($dest_file);
  90. check_name_length($file_name);
  91. }
  92. else
  93. {
  94. celebrate_death($dest_file, $upload_method);
  95. }
  96. }
  97. else if ($upload_method == 2)
  98. {
  99. $download = file_get_contents($upload_url);
  100. if (file_put_contents($dest_file, $download))
  101. {
  102. write_metadata($dest_file, $_POST["file_desc"], $upload_url . "\n\t" . $_POST["file_source"]);
  103. celebrate($dest_file);
  104. check_name_length($file_name);
  105. }
  106. else
  107. {
  108. celebrate_death($dest_file, $upload_method);
  109. }
  110. }
  111. else if ($upload_method == 0)
  112. {
  113. echo("\t<p class=\"uppercase\">(upload something next time, my dumb, sweet honey-pie <3)<p>");
  114. celebrate_death("n/a", "smartassery");
  115. }
  116. else
  117. {
  118. celebrate_death($dest_file, $upload_method);
  119. }
  120. }
  121. ?>
  122. </main>
  123. <?php
  124. include("footer.html");
  125. ?>