2

pecl_http の http_post_fields に同様の機能はありますか? 私の現在のホストは、http://pear.php.net/から拡張機能のみをインストールします(理由はわかりませんが、ssh アクセスではなく Web GUI を持っていないため、そこから入手できる拡張機能のみをインストールできます)。

ここに私のコードがあります

<?php
    $files = array(
        array(
            'name' => 'torrent',            // Don't change
            'type' => 'application/x-bittorrent',
            'file' => '0-273-70244-0.pdf.torrent'           // Full path for file to upload
        )
    );

    $http_resp = http_post_fields( 'http://torcache.net/autoupload.php', array(), $files );
    $tmp = explode( "\r\n", $http_resp );
    $infoHash = substr( $tmp[count( $tmp ) - 1], 0, 40 );
    var_dump($infoHash);
    unset( $tmp, $http_resp, $files );

現在、これは http_post_fields の未定義の関数を取得しているため機能しません

4

2 に答える 2

2

トレントをtorcacheにアップロードするには、次を使用します。

<?php
$upload_result = curl_upload('http://torcache.net/autoupload.php','torrent','/absoulte_full_path_to_torrent/torrent.torrent');

function curl_upload($url,$fileFormAttribute,$file){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        $post = array($fileFormAttribute=>"@".$file);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
        $response = curl_exec($ch);
        return $response;
}
?>

$upload_result成功した場合はトレントハッシュが含まれ、トレントへの絶対パスでない場合は失敗します。

于 2012-06-15T06:31:19.707 に答える