is there a similar function for http_post_fields from pecl_http? my current host only installs extensions from http://pear.php.net/ (not sure why, but i don't have ssh access but rather a web gui, and can only install extensions that are avai. from there)
在pecl_http中是否有类似的http_post_fields函数?我现在的主机只安装http://pear.php.net/(不知道为什么,但是我没有ssh访问,而是一个web gui,只能安装avai的扩展。从那里)
here is my code
这是我的代码
<?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 );
currently this doesn't work as im getting an undefined function for http_post_fields
目前,对于http_post_fields,我得到一个未定义的函数。
2 个解决方案
#1
2
To upload torrents to torcache I just use:
上传torrents到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
will contain the torrent hash if success, it will fail if its not the absolute path to the torrent.
$upload_result将包含种子散列,如果成功,它将会失败,如果它不是种子的绝对路径。
#2
2
There are a bunch of ways to post data from PHP, here are a couple to get you started:
有很多方法可以从PHP中发布数据,这里有一对让你开始的方法:
Streams
流
Use a stream context to open (with fopen) a URL with the post data you want to send
使用一个流上下文打开(使用fopen)一个URL和您想要发送的post数据。
function do_post($url, $data)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
Code sample adapted from Wez Furlong.
代码样本改编自Wez Furlong。
CURL
旋度
To use CURL the PHP extension will need to be available, this is more common than not these days but depends on your host.
要使用CURL, PHP扩展将需要可用,这比现在更常见,但取决于您的主机。
function do_post($url, $data)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
Code sample adapted from Lorna Jane.
代码样本改编自Lorna Jane。
#1
2
To upload torrents to torcache I just use:
上传torrents到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
will contain the torrent hash if success, it will fail if its not the absolute path to the torrent.
$upload_result将包含种子散列,如果成功,它将会失败,如果它不是种子的绝对路径。
#2
2
There are a bunch of ways to post data from PHP, here are a couple to get you started:
有很多方法可以从PHP中发布数据,这里有一对让你开始的方法:
Streams
流
Use a stream context to open (with fopen) a URL with the post data you want to send
使用一个流上下文打开(使用fopen)一个URL和您想要发送的post数据。
function do_post($url, $data)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
Code sample adapted from Wez Furlong.
代码样本改编自Wez Furlong。
CURL
旋度
To use CURL the PHP extension will need to be available, this is more common than not these days but depends on your host.
要使用CURL, PHP扩展将需要可用,这比现在更常见,但取决于您的主机。
function do_post($url, $data)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
Code sample adapted from Lorna Jane.
代码样本改编自Lorna Jane。