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');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法