Curl error while loading file "formatting data could not be created"

When I try to download a file with php and curl, the error "could not create formpost data" occurs. I know that an error occurs if the file path is incorrect

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

test.php and test.jpg in the same folder. But if I change the path to the physical path, the code will work well

test.php
...
$postcontent['files'] = '@F:\xampp\htdocs\upload\test.jpg';
...
+5
source share
1 answer

Try to always use the absolute path, as it was in your second example, which works.


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

  • dirname(__FILE__)to get the path to the directory that contains the file in which it is written
  • PHP >= 5.3: __DIR__, .


, , , - :

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

, PHP < 5.3:

$postcontent['files'] = '@' . dirname(__FILE__) . '/test.jpg';
+6

All Articles