2017-05-20 177 views
0

我有我的網站http://domain1.com,我想從另一個域http://domain2.com/uploads/data.zip下載一些.zip文件,但沒有下載並顯示302移動了臨時錯誤。我正在使用cURL代碼。如何使用PHP下載.zip文件

header('Access-Control-Allow-Origin: http://www.domain2.com'); 
header('Content-Length: '.filesize($response)); 
header('Content-Type: application/zip'); 
header('Content-Transfer-Encoding: Binary'); 
header("Content-Disposition: attachment; filename=my.zip"); 
//readfile($response); 
header("Location:$response"); 
+0

其中是捲曲代碼?? –

+1

可能的重複[有沒有辦法使用命令行跟蹤重定向cURL](http://stackoverflow.com/questions/18474690/is-there-a-way-to-follow-redirects-with-command-line-捲曲) – TomTom101

回答

0

只需在項目根目錄下創建一個php文件。像「test.php」

現在在「test.php」文件中添加以下代碼。

file_put_contents("zipname.zip", fopen("http://domain2.com/uploads/data.zip", 'r')); 

這是使用php下載文件的最快和最簡單的方法。

下面文章更詳細

https://thecodingstuff.com/php-download-archive-file-from-url/

+0

你好,SP索尼,這是爲你工作? –

+0

是的爲我工作 –

+0

但不工作,當我在ajax中使用此代碼 –