简体   繁体   English

PHP通过直接链接下载文件并将其保存在我的服务器上

[英]PHP download a file through direct link and save it on my server

I'm trying to run PHP script (from a Linux server) that will download a file through direct download link and save it on my server. 我正在尝试运行PHP脚本(从Linux服务器),该脚本将通过直接下载链接下载文件并将其保存在我的服务器上。

here is the script I'm using: 这是我正在使用的脚本:

<?php

    $url  = 'http://download.maxmind.com/app/geoip_download?edition_id=108&date=20131015&suffix=zip&license_key=XXXXXXXXXXX';
    $path = '/apps/test/';

    $fp = fopen($path, 'w');

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_FILE, $fp);

    $data = curl_exec($ch);

    curl_close($ch);
    fclose($fp);
?>   

for some reason it doesn't work for me, any suggestions ? 由于某种原因,它对我不起作用,有什么建议吗?

为什么不使用:

shell_exec("wget -P /target/directory/ http://download.link.com/download.zip");

Try this 尝试这个

$url = 'http://download.maxmind.com/app/geoip_download?edition_id=108&date=20131015&suffix=zip&license_key=XXXXXXXXXXX';
$path = '/apps/test/';
$filepath = $path .'file.zip';
$data = file_get_contents($url);
file_put_contents($filepath, $data);

您需要验证防火墙上的端口是否已打开,并使用以下命令:(这也会下载原始格式的文件)

shell_exec("wget -P /apps/birst/php_test_scripts/ --content-disposition "."'"."https://download.maxmind.com/app/geoip_download?edition_id=108&suffix=zip&license_key=XXXXXXXX"."'");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM