I'm having issues downloading an excel file onto my web server from a URL using PHP. The file is publicly accessible on a Microsoft Sharepoint server and downloads automatically when accessed directly via the link. Here is my code:
$url = 'https://example.sharepoint.com/somefile.xlsx?download=1';
$file = file_put_contents('template.xlsx', file_get_contents($url));
The script successfully creates the template.xlsx file on the server, however the file itself is 0 bytes and when I try to open it I get an error along the lines of "Excel cannot open the file because the file format or file extension is invalid". What am I missing?
Object moved to here.
– sverdon May 24 '22 at 22:21