file - How to force download web content to server using php
Get the solution ↓↓↓Solution:
Assuming you've phrased your question correctly, and you actually want to save on server instead of client.
You could use output buffering to capture the output and then save it in a file of your choosing
http://www.php.net/manual/en/function.ob-start.php
An example from the manual page (changed to save the file)
<?php
function callback($buffer)
{
//save the content
$filename = 'grab/test.txt';
file_put_contents($filename, $buffer);
}
ob_start("callback");
?>
<html>
<body>
<p>test</p>
<p>second test</p>
</body>
</html>
<?php
ob_end_flush();
?>
Answer
Solution:
"Save it in the web server" ? Do you mean the client should be prompted to save the response as a file on her local system? In that case use theContent-Disposition
header:
header('Content-Disposition: attachment; filename="text1.txt"');
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: composer detected issues in your platform: your composer dependencies require a php version ">= 8.0.2".
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.