Php 将$\文件发送到远程url并获取XML响应
我想模拟以下表单并获得xml响应:Php 将$\文件发送到远程url并获取XML响应,php,forms,file,Php,Forms,File,我想模拟以下表单并获得xml响应: <form action="https://s7ugc3.scene7.com/ugc/image?op=upload&upload_token=<?php //echo CDN::getS7Token(); ?>&company_name=usineadesign" method="post" enctype="multipart/form-data"> <p>
<form action="https://s7ugc3.scene7.com/ugc/image?op=upload&upload_token=<?php //echo CDN::getS7Token(); ?>&company_name=usineadesign" method="post" enctype="multipart/form-data">
<p>
Formulaire d'envoi de fichier :<br />
<input type="file" name="image" /><br />
<input type="submit" value="Envoyer le fichier" />
</p>
</form>
谢谢所有能帮助我的人 我建议您使用cURL发布到远程HTTP服务器。您需要相应地设置POSTDATA。我使用此函数从HTTP服务器发送/获取数据:
function get_page_by_curl($searchUrl, $post=false, $postParams="")
{
print " " . $searchUrl;
global $errMsg;
//$userAgent = "Googlebot/2.1( http://www.googlebot.com/bot.html)";
$userAgent = "Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.5 Robot";
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL, $searchUrl);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_NOPROGRESS, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
if($post)
{
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postParams);
}
$htmlPage = false;
do
{
$htmlPage = curl_exec($ch);
$errno = curl_errno($ch);
if($errno == 28)
{
print ".";
flush();
sleep(SLEEP_TIME);
}
elseif($errno == 7)
{
print "*";
flush();
sleep(SLEEP_TIME);
}
elseif($errno == 6)
{
print "+";
flush();
sleep(SLEEP_TIME);
}
elseif($errno != 0)
{
$errMsg = $errno . ": " . curl_error($ch);
}
}
while(!$htmlPage && $errno == 28);
return $htmlPage;
}
您应该可以这样称呼它:
$xml = get_page_by_curl($url, true, 'image=@/full/path/to/file&submit=Envoyer+le+fichier');
你在问什么?你是想把图片上传到另一台服务器上,还是只是想返回上传图片的URL?我想他是想把文件上传到远程服务器上——基本上是在模仿提交表单。第一次使用stackoverflow时,我被评论/回答搞糊涂了。Aleks G是对的,我只是想模仿一个提交表单(我使用一个api,它应该接收一个带有图片的表单),然后api上传我通过$u文件发送的图片,响应是一个带有图片路径的xml。我只想做一个php,因为我要上传大约10000张图片,所以我不能一张一张地上传。不幸的是,答案似乎没有给出任何结果:(@user842701“答案似乎没有给出任何结果”是什么意思。您得到了什么输出?任何错误/etc?answer=response抱歉,我太累了,无法将法语和英语混合在一起。我的实际脚本没有得到任何输出,尽管在本地测试中,我确实通过脚本发送了$u文件,但…它无法工作
$xml = get_page_by_curl($url, true, 'image=@/full/path/to/file&submit=Envoyer+le+fichier');