可能的重复:
不使用表单将文件上传到服务器? https://stackoverflow.com/questions/6036799/upload-a-file-to-server-without-using-a-form
我能够在命令行上成功运行:
curl -v -H "a-token: myTokenValue" -H "content-type: application/xml" -X POST --data-binary @/tmp/myfile_2_3.xml -A "My Wonderful Agent" http://example.com/url
我如何在 PHP 中得到这个?
更新:使用 POST 上传文件:-)
$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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)