Php file download to local from url
Using it, you can easily connect to a remote server and download files to your local machine. It allows to send http post request and get request in php as well. Executing a basic curl request will simply return the data to the output stream. But we don't want that.
Instead, we must assign it to a php variable, which we can write it to the disk. But there is a problem with this method. Below we will see the right way to download remote files with curl. I need to force the user to download the file, instead of just linking to it, since that begins playing a file in the browser sometimes.
The problem is, the video files are stored on a separate server. The key is the header. You need to send the header along with the download and it will force the 'Save File' dialog in the user's browser.
Toggle navigation. With this the user doesn't need to wait the server to download entirely the file before starting himself the download. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 5 years, 7 months ago. Active 5 years, 7 months ago. Viewed 12k times.
R2D2 R2D2 2, 4 4 gold badges 22 22 silver badges 42 42 bronze badges. We have no control over the remote hosting server, only the main website. If you left click on the file, it will try to play in the user's browser. This is not what we need to happen. These links need to be "download" links for the user to download the file to their machine, not play the file.
If you have no control over the server, then there's little you can do. Without copying the files to your own server, the only solution is to use your server as a kind of proxy so that you can set the appropriate headers. Trouble is, PHP would have to retrieve the remote file each time. This would save you storage space, but obviously not bandwidth. Your user would also have to wait for your server to download the file.