Hello. I'm using version 1.16, and I'm trying to use curl to call the API to upload files specified in a form by the user. So, the user submits via a POST the file they want to upload, and the php copies that file to a temporary spot on the server. I then use curl to tell the API to upload that file, but it says
<error code="uploaddisabled" info="Uploads are not enabled...
Even though I can totally upload through Special:Upload just fine. Here's the curl (this is after obtaining an edit token in code that works fine as a setup for creating new articles):
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookiefile.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookiefile.txt');
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: multipart/form-data"));
curl_setopt($ch, CURLOPT_URL, "http://$server_name/w/api.php?action=upload&token=$edittoken&filenam... filename&url=http://$server_name/upload_tmp/$filename");
I'm also confused as to how to call it using the 'file' option instead, as the manual says if takes 'file contents', and the examples has 'file=file_contents_here'. When I try that method with the curl
curl_setopt($ch, CURLOPT_URL, "http://$server_name/w/api.php?action=upload&token=$edittoken&filenam... filename&file=file_contents_here");
then I get the error:
<error code="missingparam" info="One of the parameters sessionkey, file, url is required"
So, what's 'file contents' supposed to contain? Thanks for the help.
Will Preston
Network Administrator
OLSON KUNDIG ARCHITECTS 206.624.5670
olsonkundigarchitects.com http://www.olsonkundigarchitects.com/
On Sat, May 29, 2010 at 12:02 AM, Will Preston Will@olsonkundigarchitects.com wrote:
Hello. I’m using version 1.16, and I’m trying to use curl to call the API to upload files specified in a form by the user. So, the user submits via a POST the file they want to upload, and the php copies that file to a temporary spot on the server. I then use curl to tell the API to upload that file, but it says
<error code="uploaddisabled" info="Uploads are not enabled…
You need to enable upload-by-url, $wgAllowCopyUploads iirc
So, what’s ‘file contents’ supposed to contain? Thanks for the help.
The content of the file wrapped in a valid multipart/form-data request.
Bryan
Will Preston wrote:
curl_setopt($ch, CURLOPT_URL,
"http://$server_name/w/api.php?action=upload&token=$edittoken&filenam...");
Are these variables already urlencoded?
if you are using CURLOPT_POST, then you will want to be using CURLOPT_POSTFIELDS, and not cram that all in the url you are posting to (also is a little better privacy)
http_build_query() is your friend here
mediawiki-api@lists.wikimedia.org