Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP通过url下载并重命名文件_Php_Download - Fatal编程技术网

使用PHP通过url下载并重命名文件

使用PHP通过url下载并重命名文件,php,download,Php,Download,我有这个网址 www1.intranet.com/reportingtool.asp?设置=var&export=ok 在那里我可以下载一份报告。报告的文件名包括时间戳。e、 g.123981098298.xls并且每次下载时都会有所不同 我想要一个具有以下功能的脚本: <?php //Download the File //rename it to **report.xls** //save it to a specified place ?> 在搜索stackoverf

我有这个网址

www1.intranet.com/reportingtool.asp?设置=var&export=ok

在那里我可以下载一份报告。报告的文件名包括时间戳。e、 g.123981098298.xls并且每次下载时都会有所不同

我想要一个具有以下功能的脚本:

<?php
//Download the File

//rename it to **report.xls**

//save it to a specified place
?>

在搜索stackoverflow和谷歌搜索这个主题后,我没有任何想法:(


这通常是可能的吗?

根据您的安全设置,这可能不起作用,但这是一个简单的示例:

<?php
$file = file_get_contents('http://www1.intranet.com/reportingtool.asp?settings=var&export=ok');
file_put_contents('/path/to/your/location/report.xls', $file);
最简单的场景
您可以下载包含
文件\u获取\u内容的报告

$report = file_get_contents('http://www1.intranet.com/reportingtool.asp?...');
file_put_contents('/some/path/report.xls', $report);
并使用
file\u put\u contents
将其保存到本地(在运行PHP的机器上):

$report = file_get_contents('http://www1.intranet.com/reportingtool.asp?...');
file_put_contents('/some/path/report.xls', $report);
更多选择
  • 如果下载需要对HTTP请求进行控制(例如,因为您需要使用Cookie或HTTP身份验证),则必须通过该方式完成下载,从而实现对请求的完全自定义
  • 如果报告的大小较大,则可以将其直接流式传输到目的地,而不是分三步执行读取/存储/写入操作(例如,使用
    fopen
    /
    fread
    /
    fwrite

这是绝对可能的。但是,抱歉,SO不是一个让其他人做你的工作的地方。当你在自己的实现中遇到问题时,这个地方是为了获得帮助。因此:首先学习php的最基本知识,解决这项非常简单的任务,然后,如果你真的遇到问题,请在这里询问。我们是否了解源代码B站点在允许访问报告之前需要身份验证?如果需要,类型是什么?当您说“保存到指定位置”时,会是什么样的位置?在运行PHP的服务器上?在客户端上(如果您的脚本通过URL访问)?脚本将如何访问?好的@arkascha这是一个好消息,它是可能的!谢谢:)@Jon:它不需要身份验证。它只需要下载到服务器端名为“downloads”的文件夹中。稍后,脚本应该通过Cronjob自动运行:)@BrandonWamboldt:当然,我一开始就错过了。谢谢