通过PHP curl发布文件 [英] POSTing a file via PHP curl
本文介绍了通过PHP curl发布文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
将文件上传到服务器而不使用表单
我可以在命令行上成功运行:
I'am able to run this succesfully on command line:
curl -v -H :myTokenValue-Hcontent-type:application / xml-X POST --data-binary @ / tmp / myfile_2_3.xml -AMy Wonderful Agent http://example.com/url
如何在PHP中获取这个?
How do I get this in PHP?
推荐答案
UPDATE:使用POST文件上传: - )
UPDATE: Using POST with file uploading :-)
$fileContents = file_get_contents("/tmp/myfile_2_3.xml");
$defaults = array(
CURLOPT_CUSTOMREQUEST => "post",
CURLOPT_HEADER => 1,
CURLOPT_URL => "http://example.com/url",
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 4,
CURLOPT_POSTFIELDS => $fileContents,
CURLOPT_HTTPHEADER => array("a-token" => "myTokenValue", "Content-Type" => "application/xml"),
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
这篇关于通过PHP curl发布文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文