Im trying to downlaod a file with php that is located on a remote server, and having no luck. Ive tried using fopen, get_file_contents, but nothing has worked.
I am passing in a download URL, which isnt the exact file location, it is the “download url” of the file, which then forces the browser to download.
So Im thinking that is why the file fopen and file_get_contents is failing, can someone tell me what I have to do to download a file from a url with headers set to force file download.
Any help greatly appreciated!
While not technically a duplicate, this has been asked on SO before: How to get redirecting url link with php from bit.ly
Your problem is that file_get_contents does not follow redirects. See the linked answer for a solution.