prepare("SELECT pidm3u8, name FROM canales WHERE id = :channelId"); $stmt->bindParam(':channelId', $channelId); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); $pidM3U8 = $row['pidm3u8']; $name = $row['name']; // Get the value of the name column // Check if the PIDs are valid if ($pidM3U8) { // Execute the command to stop the N_m3u8DL-RE process $commandM3U8 = 'kill ' . $pidM3U8; exec($commandM3U8); // Update the database to clear the PID values and time_started $stmt = $db->prepare("UPDATE canales SET pidm3u8 = NULL, time_started = NULL WHERE id = :channelId"); $stmt->bindParam(':channelId', $channelId); $stmt->execute(); // Remove all temp files $binDir = __DIR__; // Get the absolute path of the current directory $folderPath = $binDir . '/../bin/temp/' . $name . '/'; // Construct the folder path using $name variable deleteFiles($folderPath); } // Function to recursively delete files and subdirectories function deleteFiles($path) { foreach (glob(rtrim($path, "/") . '/*') as $file) { if (is_dir($file)) { deleteFiles($file); } else { unlink($file); } } rmdir($path); } ?>