Jump to content

[SOLVED] curl file upload - failed creating formpost data error


light893

Recommended Posts

Hello,

 

I've been banging my head on this for the past day. I have looked in the php docs and found the example below which I copied. I tried on 2 different servers and I get the error:

 

"failed creating formpost data".

 

So it seems to be erroring before the information is even sent via curl. 

 

I have the file "dog.txt" in the same directory as my php script initiating the send. There seems to be something that I am just missing and can't figure it out.

 

Any advice would be appreciated. I have tried on my local machine using Apache and on my remote server using Windows IIS with the same error.

 

 

[pre]<?php

  $postData = array();

 

  $postData['uploaded'] = "@dog.txt";

  $postData['submit'] = "UPLOAD";

  $postData['max_file_size'] = "300000";

 

  $ch = curl_init();

  curl_setopt($ch, CURLOPT_URL, "http://www.mydomain.com/scripts/curlTest/upload.php" );

  curl_setopt($ch, CURLOPT_POST, 1 );

  curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  $postResult = curl_exec($ch);

 

  if (curl_errno($ch)) {

      print curl_error($ch);

  }

  curl_close($ch);

  print "$postResult";

?>[/pre]

Link to comment
Share on other sites

I was able to solve the problem in case it may help anyone else. I was referencing the location incorrectly. In the file sending, it should be:

 

[pre]$file =  "D:\htdocs\scripts\curlTest\send2.php";

 

$postData['uploaded'] = "@$file";

$postData['submit'] = "UPLOAD";

$postData['max_file_size'] = "300000";[/pre]

 

 

 

and in the file receiving the call, it should be:

 

[pre]$target = "upload\\";

 

$target = $target . basename( $_FILES['uploaded']['name']) ;[/pre]

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.