因为公司项目用java做的,需要我这边用php上传文件。只给了个接口,参数都不明确,然后这边不提交表单,在生成pdf之后就立马上传。用了php+curl,总是没上传成功,这里看到了篇文章http://blog.sina.com.cn/s/blog_709475a101013dlf.html,希望可以借鉴。还有这篇http://www.cnblogs.com/jackluo/p/4113255.html
这个帖子很好:http://tieba.baidu.com/p/3294014743
下面是test2.php的代码
$ch = curl_init();
$post_data = array(
*filename* => *qie.jpg*,
*file* => @*E:/WEB/PHP/tools/grab/qie.jpg*
);
curl_setopt($ch, CURLOPT_HEADER, false)
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_URL, *http://localhost/PHP/tools/grab/test.php*);
$info = curl_exec($ch);
curl_close($ch)
print_r($info);
下面是test.php页面的代码:
print_r($_POST);
echo *===file upload info:*;
print_r($_FILES);
下面是输出结果:
Array
(
[filename] => qie.jpg
[file] => @E:/WEB/PHP/tools/grab/qie.jpg
)
===file upload info:Array
(
)
1