如何下载和保存大文件(可能使用Zend?)

时间:2011-11-04 04:33:29

标签: php zend-framework download

我在网址http://domain.com/somefile.mxt上有一个500MB的大文件。因为它是一个大文件,我不确定哪个PHP命令更适合这个。然后如何保存呢?

P.S。文件扩展名可以是任何内容,而不仅仅是.mxt

我也在使用Zend Framework,所以如果Zend有更具体的内容,那将会有所帮助

2 个答案:

答案 0 :(得分:2)

将其下载到运行脚本的目录中(必须具有写入权限):

exec('wget http://domain.com/somefile.mxt');

要将其导入PHP脚本中的变量(不需要写入权限):

$content=file_get_contents('http://domain.com/somefile.mxt');

使用上面的方法,您可以解析文件并将输出放入本地文件中:

file_put_contents('somefile.mxt',$content);

要将文件写入磁盘,您需要在要放入的目录中具有写入权限。

答案 1 :(得分:0)

我没有使用它,但如果您使用setRawData(),似乎Zend HTTP可以处理此问题。

请参阅Zend HTTP Data Streaming,这是示例代码:

$client->setStream(); // will use temp file
$response = $client->request('GET');
// copy file
copy($response->getStreamName(), "my/downloads/file");
// use stream
$fp = fopen("my/downloads/file2", "w");
stream_copy_to_stream($response->getStream(), $fp);
// Also can write to known file
$client->setStream("my/downloads/myfile")->request('GET');