Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curl error when uploading file "failed creating formpost data"

Tags:

php

curl

When I trying to upload a file with php and curl, an error occurs "failed creating formpost data". I know that error occur when file path incorrect

test.php
...
$postcontent['files'] = '@test.jpg';
...

test.php and test.jpg in the same folder. But if I change path to physic path, code run well

test.php
...
$postcontent['files'] = '@F:\xampp\htdocs\upload\test.jpg';
...
like image 718
StoneHeart Avatar asked Jul 24 '11 08:07

StoneHeart


1 Answers

Try to always use an absolute path, like you did in your second example, which works.


Of course, you do not want to hard-code that physical path, so you will want to use either :

  • dirname(__FILE__) to get the path to the directory that contains the file in which this is written
  • Or, with PHP >= 5.3 : __DIR__ which gives exactly the same path.


So, in your case, you'd probably use something like :

$postcontent['files'] = '@' . __DIR__ . '/test.jpg';

Or, with PHP < 5.3 :

$postcontent['files'] = '@' . dirname(__FILE__) . '/test.jpg';
like image 176
Pascal MARTIN Avatar answered Oct 18 '22 09:10

Pascal MARTIN