开发者

Curl error when uploading file "failed creating formpost data"

When I trying to upload a file with php and curl, an error occurs "failed creating formpost data". I know that error o开发者_运维技巧ccur 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
  • 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';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜