php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #52331 Use of @ in CURLOPT_POSTFIELDS is new
Submitted: 2010-07-13 21:45 UTC Modified: 2010-10-23 17:05 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: dscotese at litmocracy dot com Assigned: kalle (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.3.2 OS: Linux/Windows I think
Private report: No CVE-ID: None
 [2010-07-13 21:45 UTC] 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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-26 02:13 UTC] 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-26 08:07 UTC] 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 12:27 UTC] 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-10-20 05:14 UTC] kalle@php.net
-Status: Open +Status: Feedback
 [2010-10-20 05:14 UTC] kalle@php.net
Which version of cURL are you experincing this limitation?
 [2010-10-20 05:44 UTC] dscotese at litmocracy dot com
-Status: Feedback +Status: Open
 [2010-10-20 05:44 UTC] dscotese at litmocracy dot com
curl
cURL support 	enabled
cURL Information 	7.19.6
Age 	3
Features
AsynchDNS 	No
Debug 	No
GSS-Negotiate 	No
IDN 	Yes
IPv6 	No
Largefile 	Yes
NTLM 	Yes
SPNEGO 	No
SSL 	Yes
SSPI 	No
krb4 	No
libz 	Yes
CharConv 	No
Protocols 	tftp, ftp, telnet, dict, ldap, ldaps, http, file, https, ftps
Host 	i686-pc-mingw32
SSL Version 	OpenSSL/0.9.8l
ZLib Version 	1.2.3
 [2010-10-23 17:05 UTC] kalle@php.net
Automatic comment from SVN on behalf of kalle
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=304665
Log: Fixed bug #52331 (Use of @ in CURLOPT_POSTFIELDS is new)
 [2010-10-23 17:05 UTC] kalle@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: kalle
 [2010-10-23 17:05 UTC] kalle@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2010-10-23 22:48 UTC] dscotese at litmocracy dot com
Ron wrote:

   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().

Wouldn't this simulate the submission of a form in which an <input> of type='file' has been submitted with the enter key, and the data returned to the server is an encoded file as the "value" in the name-value pair with the name "file"?  That would be different from sending the file itself as the post data, not encoded, but rather relying only on the header to indicate its length.  I don't know how such a a post data could be created by a <form>  - I doubt it's possible.  I do know that there are servers that expect that kind of post data though.
 [2020-02-07 06:08 UTC] phpdocbot@php.net
Automatic comment on behalf of kalle
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=c19f9a7c23cfb4493ab3a78bd07342db91e16267
Log: Fixed bug #52331 (Use of @ in CURLOPT_POSTFIELDS is new)
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 03:00:02 2026 UTC