Doc #52331 [Opn->Fbk]: Use of @ in CURLOPT_POSTFIELDS is new

From: Date: Wed, 20 Oct 2010 03:14:26 +0000
Subject: Doc #52331 [Opn->Fbk]: Use of @ in CURLOPT_POSTFIELDS is new
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-5264@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=52331&edit=1 ID: 52331 Updated by: kalle@php.net Reported by: dscotese at litmocracy dot com Summary: Use of @ in CURLOPT_POSTFIELDS is new -Status: Open +Status: Feedback Type: Documentation Problem Package: Documentation problem Operating System: Linux/Windows I think PHP Version: 5.3.2 Block user comment: N New Comment: Which version of cURL are you experincing this limitation? Previous Comments: ------------------------------------------------------------------------ [2010-07-26 12:27:30] ross@php.net If you're setting POSTFIELDS as a string you need to encode like so: curl_setopt($ch, CURLOPT_POSTFIELDS, "file=@/home/ross/image.png"); For example, using http_build_query(). ------------------------------------------------------------------------ [2010-07-26 08:07:12] dscotese at litmocracy dot com Yes, that is what I'm referring to. I'm also referring to this form of it: <?php curl_setopt($ch, CURLOPT_POSTFIELDS, "@/home/ross/photo.jpg"); ?> Note that in the second form, PHP expects the string to contain properly encoded data. I'm not entirely sure if this second form is supported in any version of PHP (as insinuated in my final paragraph). I also never figured out how to post a comment but still honor php.net's request not to document bugs in the comments, so I didn't post the apparent requirement that the @-prefixed path be passed as an array. I believe there are servers that want an XML file posted, but don't want it posted as part of a name-value pair. ------------------------------------------------------------------------ [2010-07-26 02:13:30] ross@php.net Not entirely sure of the bug here, are you referring to something like this: <?php curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => "@/home/ross/photo.jpg")); ?> Are you including the @ inside the string quotes? @ can also be used to suppress error output, which might be confusing PHP if you have it like so: @"/home/ross/...". ------------------------------------------------------------------------ [2010-07-13 21:45:38] dscotese at litmocracy dot com Description: ------------ The CURLOPT_POSTFIELDS option supports the use of @ to indicate that a file should be sent as part of the post data, but the documentation does not specify what is the earliest version that supports this feature. I believe that my version of PHP does not support the use of the @ sign at the beginning of a data value in CURLOPT_POSTFIELDS, but because the documentation makes it seem like it has always been there, I can't verify this. I have PHP 5.1.2 in production (we're chickens when it comes to upgrading), but 5.2.5 on my dev machine (running XAMPP). In the XAMPP 5.2.5 version, the @ feature only works if the POST data is passed as an array. That should be in the docs too. I'm adding some comments for future readers. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52331&edit=1

« previous php.doc.bugs (#5264) next »