curl icon indicating copy to clipboard operation
curl copied to clipboard

CURLOPT_FILE

Open smohring opened this issue 10 years ago • 1 comments

Hey guys,

I got a strange behavior when using Jyggen Curl in Laravel to download some JPEGs. Problem was, that the file got downloaded, but was corrupted (the headers i think)

I took the Basic curl usage, made the same options and request - and it worked! Had no time for further debugging, but here's what I did:

NON working example:

$fp = fopen ($dirTarget.$filename, 'wb+');
$request = new Request($uriSrc);
$request->setOption(CURLOPT_BINARYTRANSFER, 1);
/* Protected Option. Unable to set...
$request->setOption(CURLOPT_RETURNTRANSFER, 1);*/
$request->setOption(CURLOPT_FILE, $fp);
$request->execute();
fclose($fp);  

WORKING example:

$fp = fopen ($dirTarget.$filename, 'wb+');
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $uriSrc);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FILE, $fp);
$result = curl_exec($curl);
fclose($fp);

Any Ideas?

Regards, Steffen

smohring avatar Mar 09 '15 13:03 smohring

Strange, haven't encountered this, but can't say I've uploaded files with the library either. Is this also an issue when using the CurlFile class (see #15 for example usage)?

I'll look into it.

jyggen avatar Mar 16 '15 13:03 jyggen