开发者

send $_FILE to distant url and get the XML response

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

<form action="https://s7ugc3.scene7.com/ugc/image?op=upload&u开发者_C百科pload_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 !


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');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜