How can a simple HTTP request be made to retrieve a file from an external server and save it on a local server using PHP?
To retrieve a file from an external server and save it on a local server using PHP, you can use the `file_get_contents()` function to fetch the file content and then use the `file_put_contents()` function to save it locally.
<?php
$url = 'http://www.example.com/file.txt';
$localFile = 'localfile.txt';
$content = file_get_contents($url);
file_put_contents($localFile, $content);
?>
Related Questions
- What are the potential pitfalls of sending data to different PHP scripts for different actions like reading, updating, and deleting?
- What best practices should be followed to prevent security vulnerabilities when handling file uploads in PHP?
- What are the potential pitfalls of not implementing a 301 redirect correctly in PHP?