1 回答
TA贡献1111条经验 获得超0个赞
我自己又回答了一个。我必须停止在这里运行我的最后一个选择,无论如何,这对于那些需要它的人来说是解决方案。一小时后我得到了它,我衷心感谢 php.net!
解决方案:
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$dir = new DirectoryIterator('../../uploads');
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot()) {
$getthelist = $fileinfo->getFilename();
$fp = fopen('../../uploads/' . $getthelist, 'rb');
$data = '';
while (!feof($fp)) {
$data .= fread($fp, 8192);
}
fclose($fp);
$arr = bdecode($data);
if ($arr === false) {
die('invalid torrent');
}
if (!array_key_exists('info', $arr)) {
die('invalid torrent');
}
$arr['info']['private'] = 1;
$infobc = bencode($arr['info']);
if ($infobc === false) {
die('bencoding error');
}
$info_hash = sha1($infobc);
$total_size = 0;
if (array_key_exists('files', $arr['info'])) {
foreach ($arr['info']['files'] as $file) {
if (array_key_exists('length', $file)) {
$total_size += $file['length'];
}
}
} else if (array_key_exists('length', $arr['info'])) {
$total_size += $arr['info']['length'];
}
$fileid = str_replace('.torrent', '', $getthelist);
$data = bencode($arr);
$an = array_key_exists('anonymous', $_POST);
DB::run("UPDATE torrents SET data = :data, info_hash = :info_hash, size = :total_size WHERE torrent_id = :torrentid", array(
'data' => $data,
'info_hash' => $info_hash,
'total_size' => $total_size,
'torrentid' => $fileid
)) or die('db error');
}
}
}
DirectoryIterator()就是这里的答案。虽然其他方法也有效,但它们不如这种方法有效或合乎逻辑。它按预期完美运行。
- 1 回答
- 0 关注
- 80 浏览
添加回答
举报