$value) { if (preg_match('/^updatedText_(\d+)$/', $key, $matches)) { $index = $matches[1]; $jsonData['textLayers'][$index]['updatedText'] = $value; } } // Create new filename with "-textonly-updated" suffix // If filename already ends with -textonly.json, replace with -textonly-updated.json if (strpos($filename, '-textonly.json') !== false) { $newFilename = str_replace('-textonly.json', '-textonly-updated.json', $filename); } else { // Otherwise, just add -updated before .json $newFilename = pathinfo($filename, PATHINFO_FILENAME) . '-textonly-updated.json'; } // Save the updated JSON $updatedJson = json_encode($jsonData, JSON_PRETTY_PRINT); header('Content-Type: application/json'); header('Content-Disposition: attachment; filename="' . $newFilename . '"'); echo $updatedJson; exit; } } ?>
Instructions: