1 回答

TA貢獻1111條經(jīng)驗 獲得超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 關(guān)注
- 112 瀏覽
添加回答
舉報