planbuild.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. // Settings
  3. define('UPLOAD_DIR', __DIR__ . '/pdf');
  4. define('SECRET_TOKEN', 'MY_SECRET_TOKEN');
  5. // Check token
  6. /*
  7. if ($_POST['token'] !== SECRET_TOKEN) {
  8. http_response_code(403);
  9. echo 'Invalid token';
  10. exit;
  11. }
  12. */
  13. file_put_contents('upload_debug.log', print_r($_FILES, true) . print_r($_POST, true));
  14. // Check file
  15. if (!isset($_FILES['pdf']) || $_FILES['pdf']['error'] !== UPLOAD_ERR_OK) {
  16. http_response_code(400);
  17. echo 'PDF upload failed';
  18. exit;
  19. }
  20. // Validate metadata
  21. $uuid = preg_replace('/[^a-zA-Z0-9\-]/', '_', $_POST['uuid'] ?? '');
  22. $council_reference = preg_replace('/[^a-zA-Z0-9\-]/', '_', $_POST['council_reference'] ?? '');
  23. if (!$uuid || !$council_reference) {
  24. http_response_code(400);
  25. echo 'Missing UUID or council reference';
  26. exit;
  27. }
  28. // Ensure upload directory exists
  29. $save_dir = UPLOAD_DIR . '/' . $uuid;
  30. if (!is_dir($save_dir)) {
  31. mkdir($save_dir, 0777, true);
  32. }
  33. // Save the uploaded PDF
  34. $filename = basename($_FILES['pdf']['name']);
  35. $target_path = $save_dir . '/' . $filename;
  36. if (move_uploaded_file($_FILES['pdf']['tmp_name'], $target_path)) {
  37. http_response_code(200);
  38. echo "Uploaded: $filename";
  39. } else {
  40. http_response_code(500);
  41. echo 'Failed to save file';
  42. }