使用PHP从URL下载.xlsx文件

发布于 2025-01-31 20:16:54 字数 360 浏览 2 评论 0原文

我使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文