doujiu8826 2011-07-13 13:11
浏览 58
已采纳

将$ FILE发送到远程URL并获取XML响应

I want to simulate the following form and get the xml response:

<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>

The picture is on the server and I have an easy access to its path ! I want to create a function that would look like that

uploadtoscen7($path_to_image)
{
  ...
  return $url;
}

Thanks to anyone who could help me !

  • 写回答

1条回答 默认 最新

  • duandanbeng1829 2011-07-13 13:21
    关注

    I suggest you use cURL to post to remote HTTP server. You'll need to set the POSTDATA accordingly. I use this function to send/get data from HTTP server:

    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;
    }
    

    You should be able to then call it like this:

    $xml = get_page_by_curl($url, true, 'image=@/full/path/to/file&submit=Envoyer+le+fichier');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上