上传文件时发生错误“创建表单数据失败” [英] Curl error when uploading file "failed creating formpost data"

查看:198
本文介绍了上传文件时发生错误“创建表单数据失败”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用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和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 __)获取包含写入文件的目录的路径

  • 或者,使用PHP> = 5.3: __ DIR __ 完全相同的路径。

  • 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.



所以,在你的情况下,你可能会使用类似: / p>


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

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

5.3:

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

这篇关于上传文件时发生错误“创建表单数据失败”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆