note 112113 added to function.curl-setopt
| From: | Madcat | Date: | Mon, 06 May 2013 15:14:54 +0000 |
| Subject: | note 112113 added to function.curl-setopt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194712@lists.php.net to get a copy of this message | ||
If you have a mixture of strings starting with @ (at character) and files in CURLOPT_POSTFIELDS you
have a problem (such as posting a tweet with attached media) because curl tries to interpret
anything starting with @ as a file.
<?php
$postfields = array(
'upload_file' => '@file_to_upload.png',
'upload_text' => '@text_to_upload'
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://example.com/upload-test');
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
curl_exec($curl);
curl_close($curl);
?>
To get around this, prepend the text string with the NULL character like so:
<?php
$postfields = array(
'upload_file' => '@file_to_upload.png',
'upload_text' => sprintf("\0%s", '@text_to_upload')
);
?>
Original source: http://bit.ly/AntMle
----
Server IP: 69.147.83.199
Probable Submitter: 115.87.217.79 (proxied: 115.87.217.79)
----
Manual Page -- http://php.net/manual/en/function.curl-setopt.php
Edit -- https://master.php.net/note/edit/112113
Del: integrated -- https://master.php.net/note/delete/112113/integrated
Del: useless -- https://master.php.net/note/delete/112113/useless
Del: bad code -- https://master.php.net/note/delete/112113/bad+code
Del: spam -- https://master.php.net/note/delete/112113/spam
Del: non-english -- https://master.php.net/note/delete/112113/non-english
Del: in docs -- https://master.php.net/note/delete/112113/in+docs
Del: other reasons-- https://master.php.net/note/delete/112113
Reject -- https://master.php.net/note/reject/112113
Search -- https://master.php.net/manage/user-notes.php