PHP Curl发布数据而不是<input type =“file”/>

时间:2011-11-14 10:34:12

标签: php html curl

我目前正在使用<input type="file">发布文件。因为我无法指定

的值

<input id="content" type="file">并且必须手动浏览文件,我想知道我是否可以使用PHP Curl指定路径。

服务器是否会读取$_POST["content"]

1 个答案:

答案 0 :(得分:1)

是的,你可以这样做:

$post_params = array();
$post_params['file'] = '@'.'demo/testfile.txt';
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);

@ 对于指定这是一个要卷曲的实际文件非常重要

您将通过$ _FILES超级全局收到该文件,就像您执行了rel表单一样

$_FILES['file']

希望有所帮助

要回答您的问题,您需要文件系统上的绝对路径