0

私はあなたの優れた Web 開発の洞察を必要としています。私は Imageshack API で遊んでいましたが、フォームを使用してサーバーから imageshack サーバーに画像をアップロードすることができました。かなり紛らわしいデータが返されます。

今、私の質問は、私が必要なものを手に入れるために、それで一体何をするのかということです. 解析する必要がありますか?私は正規表現が嫌いです (しかし、必要に応じて扱います)。解析する必要がある場合、文字列全体を関数に送信するにはどうすればよいですか? 私は少し混乱しています。

<form method="post" enctype="multipart/form-data" action="http://www.imageshack.us/upload_api.php">



<p><input type="file" name="fileupload"></p>

<p><input type="text" name="tags" value="proba,test"></p>

<p><input type="text" name="key" value="xxxxxxxxxxxxxxxxxxxxxxxxxx"></p>

<p><select name="optsize">

        <option value="320x240">Small (320x240)</option>

        <option value="426x320" selected>Medium (426x320)</option>

        <option value="640x480">Big (640x480)</option>

</select></p>

<p><input type="submit" value="Go"></p>

</form>

返されるデータは次のようになります。

http://img574.imageshack.us/img574/3084/18835698.png

私の質問は、ユーザーが送信ボタンを押すたびに、そのジャンクを動的に解析し、きれいな結果を得るにはどうすればよいかということです。

4

5 に答える 5

1

CURL lib またはより簡単に Ajax 関数を使用できる動的ページを使用する必要があります。

たとえば、PHP の CURL を使用してすべてのものを渡した後、simpleXML を使用して返された XML ページから URL を取得できます。

于 2011-02-12T10:47:16.273 に答える
0

質問のタグから、返されるデータはXMLであると想定し、ネイティブのPHPSimpleXML関数を調べて応答を解析することをお勧めします。

PHPマニュアルには、作業を開始するための基本的な例が含まれています。基本的な使用法

于 2010-11-05T11:50:24.957 に答える
0

ああ、ありがとう、今わかりました。さらに調査を行ったところ、次のように curl を使用する別の方法が考えられます。

cURL を使用して「http://www.imageshack.us/upload_api.php」に投稿を送信

    $data['key'] = API_KEY;
    $data['public'] = "yes";
    $data['xml'] = "yes";
    $data['fileupload'] = '@'.$dest; 

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, 'http://www.imageshack.us/upload_api.php');
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_TIMEOUT, 600);
    /*curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);*/
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    $result = curl_exec($curl);
    curl_close($curl);
于 2010-11-05T12:44:50.197 に答える
0

必要なのはこのリンクだけです:

http://code.google.com/p/imageshackapi/source/browse/RedirectAPI.wiki?repo=wiki

これをフォームに入れる必要があります

<input type="hidden" name="success_url" value="mysite.com/success.php?var1=%s&var2=%b&var3=%i">; 
<input type="hidden" name="error_url" value="error.php">
<input type="hidden" name="optsize" id="optsize" value="200x380"/> 
<input type="hidden" name="optimage" id="optimage" value="1"/> 
<input type="hidden" name="rembar" id="rembar" value="1"/>

画像の URL を取得するには:

$img_url="http://img$var1.imageshack.us/img$var1/$var2/$var3";

サムネイルを取得するには:

$var3= str_replace (".jpg", ".th.jpg", $var3); 
$var3= str_replace (".gif", ".th.gif", $var3); 
$var3= str_replace (".png", ".th.png", $var3); 
$tumb_url="http://img$var1.imageshack.us/img$var1/$var2/$var3";
于 2012-02-16T10:06:45.080 に答える
0

これを PHP ランタイムで実行したいと考えています。

XML を取得したら、情報を取得するために使用できる小さな関数を次に示します。

/**
* parsing XML response for info about uploaded file
*   image_link  - URL address of uploaded image on imageshack server
*   thumb_link  - URL address of thumbnail of uploaded image on imageshack server
*   yfrog_link  - URL address of uploaded image on yfrog server
*   yfrog_thumb - URL address of thumbnail of uploaded image on yfrog server  
*   ad_link     - URL address of imgaeshack page with uploaded image
*   done_page   - URL address of thumbnail of uploaded image on imageshack server
*   width       - width of uploaded image [px]
*   height      - height of uploaded image [px]
*/
function getInfo($xml,$key)
{
    preg_match('/<'.$key.'>(.*)<\/'.$key.'>/', $xml, $value);    
    if (empty($value[0])) {
        return('invalid key');
    }else {
        return(strip_tags($value[0]));
    }
}

関数のソース: http://www.sourcer.cz/ci-lib/imageshack/

使用法は次のようになります。

$xml = file_get_contents('http://www.imageshack.us/upload_api.php?url=http://www.mysite.com/myimage.png');
$image_link = getInfo($xml,'image_link');
于 2010-11-05T12:03:34.947 に答える