带有没有文件名的URL的PHP将文件下载到我的服务器
我可以通过固定的URL下载CSV文件。 URL只是没有文件名。 当我在浏览器中打开URL时,会生成文件导出。CSV,大约10秒后,下载开始。 现在,我想将此导出CSV文件直接下载到我自己的服务器,
我有以下代码,但在我的情况下它不起作用。 你能帮助我吗?我的感谢很大
<?php
$url =
'https://www.example.com/product-export/link123456789';
$file_name = basename($url);
if (file_put_contents($file_name, file_get_contents($url)))
{
echo "File downloaded successfully";
}
else
{
echo "File downloading failed.";
}
?>
I can download a csv file via a fixed url. The url just doesn't have a file name.
When I open the url in a browser, the file export.csv is generated and after about 10 sec the download starts.
Now I want to download this export csv file directly to my own server,
I have the code below, but it doesn't work in my case.
Can you help me? my thanks are big
<?php
$url =
'https://www.example.com/product-export/link123456789';
$file_name = basename($url);
if (file_put_contents($file_name, file_get_contents($url)))
{
echo "File downloaded successfully";
}
else
{
echo "File downloading failed.";
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于生成的输出文件名始终是导出的。csv,我们可以使用以下来指定文件名:(
确保目录已写入 - 以便PHP可以保存文件“ export.csv”)
因此,代码将是:
对于您的cronjob,这将是:
As the generated output filename is always export.csv, we may use the following to specify the filename:
(make sure the directory is write-permitted so that the php can save the file "export.csv")
Hence, the code will be:
For your cronjob, it will be something like :