'crossorigin header in php is not working after previous php exec ffmpeg command

I am using php exec function to execute a FFMPEG command, but I am also using Javascript to send the request and they are cross origin requests, but after the exec command, while I start to send next cross origin request, it shows Access to XMLHttpRequest at 'https://www..com:550/api/adminapi' from origin 'https://www..com:8081' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. which means the cross origin header is not working in the next cross origin request after exec command, below is the code:

if (isset($_POST['crossorigin'])) {
$crossoriginallow = array();
$crossoriginallow = [
'https://www.***.com:8080', 
'https://www.***.com:8081', 
'https://www.***.com:8082'];
for ($i = 0; $i < sizeof($crossoriginallow); $i++) {
if ($crossoriginallow[$i] == $_POST['crossorigin']) {
  $crossorigin = $_POST['crossorigin'];
  break;
  }
}
header("Access-Control-Allow-Origin:$crossorigin");
header("Access-Control-Allow-Methods:GET, POST, OPTIONS, DELETE");
header("Access-Control-Allow-Headers:DNT,X-Mx-ReqToken,Keep- 
Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache- 
Control,Content-Type, Accept-Language, Origin, Accept-Encoding");
}

exec("ffmpeg -i " . $infilepath . " -c:v mpeg4 -preset veryslow - 
 c:a mp3 -q 0 " . $outfilepath /* . " 2>&1" *//* , $out */);

 $infilepathsep = explode('/', $infilepath);
 $folderpath = '';
 for ($i = 0; $i < sizeof($infilepathsep) - 1; $i++) {
 $folderpath = $folderpath . $infilepathsep[$i];
 $folderpath = $folderpath . '/';
}

 $opendirhandle = opendir($folderpath);
 closedir($opendirhandle);
 $openfilehandle = fopen($infilepath, 'r');
 fclose($openfilehandle);
 unlink(iconv("utf-8", "gbk", $infilepath));
 $result['data'] = $outfilepath;
 $result['msg'] = 'success';
 $jsonresult = json_encode($result);
 echo $jsonresult;
 ob_get_contents();
 ob_end_flush();

I does not encounter this problem before using the same code,but after I reinstall the computer it happens, May I please ask the reason if you know the problem? Thank you very much for your help!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source