views:

31

answers:

3

There are many questions and guides on how to get cURL to DO file uploads, but what I'm asking today, is how to NOT get it to do that.

According to the curl options docs on php.net, curl "knows" to attempt a file upload by when a param starts with "@" then the local file path

This is all well and fine, but what do you do if you need to POST something with the literal text that starts with @ and NOT want to do a upload?

I'm sending the post data like this

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param_array);

and my params look like this (truncated for simplicity)

Array
(
    [action] => "edit"
    [title] => "my_pagename"
    [text] => "@disabled"
)

(before anyone asks, yes, this is for a mediawiki api call, but its not relevant)

right now, the curl_exec is just returning false (failing to find the file named "disabled" to post i think)

my code path for the rest of the params, and the actual POST is 100% tested fine, and has been working otherwise for over a year, so i'm 100% sure its this upload "bug"

A: 

Completely a shot in the dark, but you might try escaping it with \

Jud Stephenson
tried it, since @ isnt an char that needs escaping, it send, and saved the literal \
Uberfuzzy
@uberfuzzy, I would probably go with Sabeen, that should work.
Jud Stephenson
+1  A: 

have you tried urlencode on that? i mean "%40disabled"

Sabeen Malik
nope, also saved the literal "%" "4" and "0" chars. its designed to let you save what ever you want, exactly as is.
Uberfuzzy
+3  A: 

I believe that if you post the query as a string, rather than an array, it should work:

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param_array));

It's a bit of a hack, unfortunately...

lonesomeday
we have a winner. that works. now that i think about it, that makes sense too. this code will never do uploads, so i'll add some catches to detect if the first char is @, to switch to query mode. thanks!
Uberfuzzy