Sometimes, we want to download a file to the server from URL with PHP.
In this article, we’ll look at how to download a file to the server from URL with PHP.
How to download a file to the server from URL with PHP?
To download a file to the server from URL with PHP, we can use the file_put_contents
function.
For instance, we write
file_put_contents("Tmpfile.zip", fopen("http://someurl/file.zip", "r"));
to call file_put_contents
function wuith the the file name to save the file as and the file that we get by calling fopen
with the URL and 'r'
for read permission.
Conclusion
To download a file to the server from URL with PHP, we can use the file_put_contents
function.