I have a code in cURL that should copy an image from a URL to my server:
$curl = curl_init( $url );
$file = fopen( $imageURL , 'wb' );
curl_setopt( $curl , CURLOPT_FILE , $file );
curl_setopt( $curl , CURLOPT_HEADER , true );
curl_setopt( $curl , CURLOPT_FOLLOWLOCATION , true );
curl_exec( $curl );
curl_close( $curl );
fclose( $file );
it doesn’t work correctly but file_put_contents() does. Is there something wrong with my cURL code?
Dont set
CURLOPT_HEADERto true. This will include the header in the output. So your image file will contain response header + image data. Remove that line or set itfalse.