LibCURL sends filename rather than file contents when I try to upload a binary file in Windows Server 2008 LibCURL sends filename rather than file contents when I try to upload a binary file in Windows Server 2008 windows windows

LibCURL sends filename rather than file contents when I try to upload a binary file in Windows Server 2008


From the documentation of curl-setopt

CURLOPT_POSTFIELDS The full data to post in a HTTP "POST" operation. To post a file, prepend a filename with @ and use the full path. The filetype can be explicitly specified by following the filename with the type in the format ';type=mimetype'. This parameter can either be passed as a urlencoded string like 'para1=val1&para2=val2&...' or as an array with the field name as key and field data as value. If value is an array, the Content-Type header will be set to multipart/form-data. As of PHP 5.2.0, value must be an array if files are passed to this option with the @ prefix. As of PHP 5.5.0, the @ prefix is deprecated and files can be sent using CURLFile. The @ prefix can be disabled for safe passing of values beginning with @ by setting the CURLOPT_SAFE_UPLOAD option to TRUE.

The behavior depends on php release and @ prefix is now deprecated.

You should use CurlFile class to set the CURLOPT_POSTFIELDS of the curl request like this :

$post['pic'] = new CurlFile('C:\\image.png');$ret = curl_setopt( $ch, CURLOPT_POSTFIELDS, $post );