TeAmEr
TeAmEr

Reputation: 4773

Curl not working as expected

in this code :

$url  = 'http://example.com/someLARGE.file';
    $path = 'test.txt';

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

    $curl = curl_init();

    //curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_FILE, $fp);
    curl_setopt ($curl, CURLOPT_URL, $url);

    curl_exec($curl);

    curl_close($curl);
    fclose($fp);

The output is written to the browser and not to the file on the server :(

Upvotes: 2

Views: 301

Answers (2)

TeAmEr
TeAmEr

Reputation: 4773

in $fp = fopen($path, 'w+'); I did not have permissions to create/write to the file .

Upvotes: 0

xkeshav
xkeshav

Reputation: 54016

try with file_put_contents

$result = curl_exec($curl);

file_put_contents($file, $result,FILE_APPEND | LOCK_EX);

file_put_contents is identical to calling fopen(), fwrite() and fclose() successively to write data to a file.

Upvotes: 1

Related Questions