diff --git a/api/capture.php b/api/capture.php index 0bf7249c1..3e1af029d 100644 --- a/api/capture.php +++ b/api/capture.php @@ -12,14 +12,17 @@ $logger->debug(basename($_SERVER['PHP_SELF'])); try { - if (!isset($_POST['style'])) { + $rawInput = file_get_contents('php://input'); + $postData = json_decode($rawInput, true); + + if (!isset($postData['style'])) { throw new Exception('No style provided'); } - if (!empty($_POST['file']) && (preg_match('/^[a-z0-9_]+\.jpg$/', $_POST['file']) || preg_match('/^[a-z0-9_]+\.(mp4)$/', $_POST['file']))) { - $file = $_POST['file']; + if (!empty($$postData['file']) && (preg_match('/^[a-z0-9_]+\.jpg$/', $postData['file']) || preg_match('/^[a-z0-9_]+\.(mp4)$/', $postData['file']))) { + $file = $postData['file']; } else { - $file = $_POST['style'] === 'video' ? Image::createNewFilename($config['picture']['naming'], '.mp4') : Image::createNewFilename($config['picture']['naming']); + $file = $postData['style'] === 'video' ? Image::createNewFilename($config['picture']['naming'], '.mp4') : Image::createNewFilename($config['picture']['naming']); if ($config['database']['file'] != 'db') { $file = $config['database']['file'] . '_' . $file; } @@ -27,7 +30,7 @@ $filename_tmp = $config['foldersAbs']['tmp'] . DIRECTORY_SEPARATOR . $file; if (file_exists($filename_tmp)) { - $random = $_POST['style'] === 'video' ? Image::createNewFilename('random', '.mp4') : Image::createNewFilename('random'); + $random = $postData['style'] === 'video' ? Image::createNewFilename('random', '.mp4') : Image::createNewFilename('random'); $filename_random = $config['foldersAbs']['tmp'] . DIRECTORY_SEPARATOR . $random; rename($filename_tmp, $filename_random); } @@ -37,16 +40,16 @@ $captureHandler->fileName = $file; $captureHandler->tmpFile = $filename_tmp; - switch ($_POST['style']) { + switch ($postData['style']) { case 'photo': $captureHandler->style = 'image'; break; case 'collage': - if (!is_numeric($_POST['collageNumber'])) { + if (!is_numeric($postData['collageNumber'])) { throw new Exception('No or invalid collage number provided.'); } - $number = $_POST['collageNumber'] + 0; + $number = $postData['collageNumber'] + 0; if ($number > $config['collage']['limit']) { throw new Exception('Collage consists only of ' . $config['collage']['limit'] . ' pictures'); @@ -72,16 +75,16 @@ break; } - if ($_POST['style'] === 'video') { + if ($postData['style'] === 'video') { $captureHandler->captureCmd = $config['take_video']['cmd']; $captureHandler->captureWithCmd(); } elseif ($config['dev']['demo_images']) { $captureHandler->captureDemo(); } elseif ($config['preview']['mode'] === 'device_cam' && $config['preview']['camTakesPic']) { $captureHandler->flipImage = $config['preview']['flip']; - $captureHandler->captureCanvas($_POST['canvasimg']); + $captureHandler->captureCanvas($postData['canvasimg']); } else { - if ($_POST['style'] === 'custom') { + if ($postData['style'] === 'custom') { $captureHandler->captureCmd = $config['take_custom']['cmd']; } else { $captureHandler->captureCmd = $config['take_picture']['cmd'];