开发者

Curl error when uploading file "failed creating formpost data"

开发者 https://www.devze.com 2023-03-22 17:58 出处:网络
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

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

精彩评论

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