Advertisement
eqeqwan21

Untitled

Sep 26th, 2024
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. public function get_fileCities()
  2.     {
  3.         $filePath = __DIR__ . '/../../cities.txt';
  4.         if (!file_exists($filePath)) {
  5.             file_put_contents($filePath, '');
  6.         }
  7.         $data = file_get_contents($filePath);
  8.         header('Content-Type: application/json');
  9.         if ($data) {
  10.             echo json_encode(explode(',', $data));
  11.         } else {
  12.             echo json_encode([]);
  13.         }
  14.     }
  15.  
  16.     public function get_updateFileCities()
  17.     {
  18.         $filePath = __DIR__ . '/../../cities.txt';
  19.         if (isset($_GET['cityIds'])) {
  20.             $cityIds = $_GET['cityIds'];
  21.  
  22.             file_put_contents($filePath, $cityIds);
  23.  
  24.             header('Content-Type: application/json');
  25.             echo json_encode(['status' => 'success']);
  26.         } else {
  27.             header('Content-Type: application/json');
  28.             echo json_encode(['status' => 'error', 'message' => 'No city IDs provided']);
  29.         }
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement