使用php通过CURL下载文件

Sup*_*r1o 0 php cookies curl file-get-contents

我需要POST cookies.txt然后使用CURL将页面下载到文本文件.这是我的FGC示例,但显然FGC对Cookie不好,所以我需要CURL.

<?php
    $file = file('source\1.txt');
    foreach ($file as $link)
    {
        $link       = trim($link);
        $link2      = "http://site-that.com/authenticates?={$link}";
        $downloaded = file_get_contents($link2);
        $myFile     = "parsed/$link" . ".txt";
        $fh = fopen($myFile, 'a') or die('Cannot open file');
        fwrite($fh, $downloaded);
    }
    $timestamp = time();
    rename('source\1.txt', "source/done/done-{$timestamp}.txt");
    echo 'Finished';
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?代码示例将非常感激.像google.com这样做的一个简单例子也很棒.另外,如果你有另一种方法可以做到这一点,那就更快了,请发帖!

kha*_*tam 5

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookieFileName); //$cookieFilename must be a path to a file with cookie data
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookieFileName);
//curl_setopt($curl, CURLOPT_COOKIE, $cookie);  //you may also use this, here $cookie is a cookie string
curl_close($curl);
$data = curl_exec($curl);
Run Code Online (Sandbox Code Playgroud)