使用PHP从URL下载.xlsx文件
我使用PHP从URL上下载Excel文件的问题。该文件可在Microsoft SharePoint服务器上公开访问,并在直接通过链接访问时自动下载。这是我的代码:
$url = 'https://example.sharepoint.com/somefile.xlsx?download=1';
$file = file_put_contents('template.xlsx', file_get_contents($url));
脚本成功地创建了服务器上的template.xlsx文件,但是文件本身为0字节,当我尝试打开它时,我会沿着“ excel无法打开文件”的行会出现错误,因为文件格式是因为文件格式或文件扩展名无效”。我想念什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论