Cannot get curl to send photos to remote API.
Remote server works fine when receiving direct submit onsite. File upload filed name is photos[]
(api runs laravel 5, with csrf disabled).
First I do this:
foreach ( $carRaw[ 'imgs' ] as $k => $v) {
$tmpFile = tempnam( '/tmp/curlfiles', 'autoge-' );
file_put_contents(
$tmpFile,
file_get_contents(
'http://' . $v[ 'ipt' ] . '/im/im-' . $v[ 'ikey' ]
)
);
$car[ 'photos' ][ $k ] = new \CURLFile( $tmpFile, 'image/png', $v[ 'ikey' ] );
}
After my sending method:
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $addCarUrl );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $car ) );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_COOKIEFILE, $cookiePath );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_VERBOSE, false );
$response = curl_exec( $ch );
curl_close( $ch );
$this->info( $response );
return $response; // 1 or 0
Problem is that all the fields are sent and saved, but never images. I must be sending them in a wrong way!
Any help?