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';
...
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__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';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With