CURL Download the Zip file - "argument is not a valid File-Handle resource"

I am trying to download a zip file from the server that I host and store it on another server using PHP and cURL. My PHP looks like this:

set_time_limit( 0 );
$ci = curl_init();
curl_setopt_array( $ci, array(
    CURLOPT_FILE    =>  '/directory/images.zip',                // File Destination
    CURLOPT_TIMEOUT =>  3600,                                   // Timeout
    CURLOPT_URL     => 'http://example.com/images/images.zip'   // File Location
) );
curl_exec( $ci );
curl_close( $ci );

Whenever I run this, I get the following error on the line CURLOPT_URL:

Warning: curl_setopt_array (): the supplied argument is not a valid File-Handle resource in ...

If I am in the file location directly in my browser, it is downloaded. Do I need to pass some header information so that he knows that this is a zip file? Is there any way to debug this?

+4
source share
1

, CURLOPT_FILE, .

$ci = curl_init();
$url = "http://domain.com/images/images.zip"; // Source file
$fp = fopen("/directory/images.zip", "w"); // Destination location
curl_setopt_array( $ci, array(
    CURLOPT_URL => $url,
    CURLOPT_TIMEOUT => 3600,
    CURLOPT_FILE => $fp
));
$contents = curl_exec($ci); // Returns '1' if successful
curl_close($ci);
fclose($fp);
+11

All Articles