Я сделал пример своей проблемы. У меня 4 файла
- index. php
- RunVia Ajax. php
- SendRequest. php
- AjaxFile . php
index. php Файл
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<button id="OK">Test Ajax</button>
<script>
$("#OK").click(function(){
$.ajax({
type: "POST",
url: 'RunViaAjax.php',
data: {data: "someData"}, // serializes the form's elements.
success: function(data){
console.log(data);
}
});
});
</script>
</body>
</html>
RunVia Ajax. php Файл
<?php
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://localhost/tester/SendRequest.php',
CURLOPT_USERAGENT => 'Codular Sample cURL Request'
]);
// Send the request & save response to $resp
$resp = curl_exec($curl);
echo $resp;
// Close request to clear up some resources
curl_close($curl);
?>
SendRequest. php Файл
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<p id="result"></p>
<script>
$.ajax({
type: "POST",
url: 'AjaxFile.php',
data: {data: "someData"}, // serializes the form's elements.
success: function(data){
$('#result').html(data);
}
});
</script>
</body>
</html>
AjaxFile. php Файл
<?php
file_put_contents("OK-Report.php", "");
echo "OK REPORT";
?>
Теперь, запустив index. php, я получаю исходный код SendRequest. php. Мне нужно запустить SendRequest. php (SendRequest. php - динамически создаваемый файл).