 |
|
|
06-21-2005, 05:27 PM
|
dl problems
|
Posts: 340
Name: Jon
Location: New York
|
Okay i have a script for torrents that goes into a db and gets the file name from the db and i always get that the file is not found
here is the code
PHP Code:
<?
require_once("../include/bittorrent.php");
dbconn();
$TID = $_GET['torrentid'];
hit_start();
if ($TID == 0) {
echo "No Torrent Specified for Download";
exit;
}
/*
if (!preg_match(':^/(\d{1,10})/(.+)\.torrent$:', $_SERVER["PATH_INFO"], $matches))
httperr();
$TID = 0 + $matches[1];
if (!$TID)
httperr();
*/
hit_count();
$res = mysql_query("SELECT filename FROM torrents WHERE id = $TID")
or die(mysql_error()) ;
$row = mysql_fetch_assoc($res);
$torrentfile = $res;
$fn = '$torrent_dir/$torrentfile';
$dl = "$torrentfile";
if (!$row || !is_file($fn) || !is_readable($fn))
httperr();
mysql_query("UPDATE torrents SET hits = hits + 1 WHERE id = $TID");
require_once "include/benc.php";
if (strlen($CURUSER['passkey']) != 32) {
$CURUSER['passkey'] = md5($CURUSER['username'].get_date_time().$CURUSER['passhash']);
mysql_query("UPDATE users SET passkey='$CURUSER[passkey]' WHERE id=$CURUSER[id]");
}
$dict = bdec_file($fn, (1024*1024));
if ( ereg("amwbt.jonspcrepair.com/announce.php", $row[scrape_url])) {
$dict['value']['announce']['value'] = "$DEFAULTBASEURL/announce.php?passkey=$CURUSER[passkey]";
}
$dict['value']['announce']['string'] = strlen($dict['value']['announce']['value']).":".$dict['value']['announce']['value'];
$dict['value']['announce']['strlen'] = strlen($dict['value']['announce']['string']);
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Content-Disposition: attachment; filename="'.$res['filename'].'"');
header("Content-Type: application/x-bittorrent");
print(benc($dict));
hit_end();
?>
]
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
|
|
|
|
06-22-2005, 07:05 AM
|
|
Posts: 297
|
as in a 404 File Not Found??? cause if thats the case it isn't PHP, you've probably put the wrong file name for one of your PHP scripts.
Or do you mean the PHP script is not finding the correct torrent file?
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill
Please visit my sites: Please login or register to view this content. Registration is FREE | Please login or register to view this content. Registration is FREE
|
|
|
|
06-22-2005, 08:49 AM
|
|
Posts: 340
Name: Jon
Location: New York
|
php is not associating the filename from the database with the actual file in the torrent folder .
Php pulls the file name from the db and i have it dispaly the name to me right now to make sure that php and the db are connecting & working which it is. so its now not finding the file in the torrent folder which were this script is/was since it did not work. THe only thing i can think of is were it changed the announce url and adds a passkey to it. then php does not recognize the file. it would be after php finds the file in the db is were the error is.
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
|
|
|
|
06-23-2005, 10:12 PM
|
|
Posts: 340
Name: Jon
Location: New York
|
still have issues. it pulls the right file name but is not finding the right file
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
|
|
|
|
07-07-2005, 04:39 PM
|
|
Posts: 340
Name: Jon
Location: New York
|
Sorry to revive this old thread but i dont feel like writing a new thread. (plus less clutter on the forums)
Okay my Download script.... does not work. in IE i get a 404 file not found. mysql get ths correct torrent name from the DB and i think navigates to the right folder were located. well for some reson it does not find the file (which is their!) as when downloading the file php changes the announce URL in the file to add the passkey for the user dl the torrent.
The dl script
PHP Code:
<?
require_once("include/bittorrent.php");
dbconn();
hit_start();
$id = $_GET["id"];
$name = $_GET["name"];
if (!$id)
httperr();
hit_count();
$res = mysql_query("SELECT name FROM torrents WHERE id = $id") or sqlerr(__FILE__, __LINE__);
$row = mysql_fetch_assoc($res);
$fn = "$torrent_dir/$id.torrent";
if (!$row || !is_file($fn) || !is_readable($fn))
httperr();
mysql_query("UPDATE torrents SET hits = hits + 1 WHERE id = $id");
require_once "include/benc.php";
if (strlen($CURUSER['passkey']) != 32) {
$CURUSER['passkey'] = md5($CURUSER['username'].get_date_time().$CURUSER['passhash']);
mysql_query("UPDATE users SET passkey='$CURUSER[passkey]' WHERE id=$CURUSER[id]");
}
$dict = bdec_file($fn, (1024*1024));
$dict['value']['announce']['value'] = "$DEFAULTBASEURL/announce.php?passkey=$CURUSER[passkey]";
$dict['value']['announce']['string'] = strlen($dict['value']['announce']['value']).":".$dict['value']['announce']['value'];
$dict['value']['announce']['strlen'] = strlen($dict['value']['announce']['string']);
$dict['value']['private']['type'] = "integer";
$dict['value']['private']['value'] = 1;
header('Content-Disposition: attachment; filename="torrents/'.$torrent['filename'].'"');
header("Content-Type: application/x-bittorrent");
header("Content-Disposition: attachment; filename=torrents/".$_GET["name"]."");
print(benc($dict));
hit_end();
?>
Or could it be my upload script?
PHP Code:
<?
require_once("include/benc.php");
require_once("include/bittorrent.php");
require "rconpasswords.php";
hit_start();
ini_set("upload_max_filesize",$max_torrent_size);
function bark($msg) {
genbark($msg, "Upload failed!");
}
dbconn();
hit_count();
loggedinorreturn();
if (get_user_class() < UC_UPLOADER)
die;
foreach(explode(":","descr:type:name") as $v) {
if (!isset($_POST[$v]))
bark("missing form data");
}
if (!isset($_FILES["file"]))
bark("missing form data");
$f = $_FILES["file"];
$fname = unesc($f["name"]);
if (empty($fname))
bark("Empty filename!");
/*
$nfofile = $_FILES['nfo'];
if ($nfofile['name'] == '')
bark("No NFO!");
if ($nfofile['size'] == 0)
bark("0-byte NFO");
if ($nfofile['size'] > 65535)
bark("NFO is too big! Max 65,535 bytes.");
$nfofilename = $nfofile['tmp_name'];
if (@!is_uploaded_file($nfofilename))
bark("NFO upload failed");
*/
$descr = unesc($_POST["descr"]);
if (!$descr)
bark("You must enter a description!");
$catid = (0 + $_POST["type"]);
if (!is_valid_id($catid))
bark("You must select a category to put the torrent in!");
if (!validfilename($fname))
bark("Invalid filename!");
if (!preg_match('/^(.+)\.torrent$/si', $fname, $matches))
bark("Invalid filename (not a .torrent).");
$shortfname = $torrent = $matches[1];
if (!empty($_POST["name"]))
$torrent = unesc($_POST["name"]);
$tmpname = $f["tmp_name"];
if (!is_uploaded_file($tmpname))
bark("eek");
if (!filesize($tmpname))
bark("Empty file!");
$dict = bdec_file($tmpname, $max_torrent_size);
if (!isset($dict))
bark("What the **** did you upload? This is not a bencoded file!");
function dict_check($d, $s) {
if ($d["type"] != "dictionary")
bark("not a dictionary");
$a = explode(":", $s);
$dd = $d["value"];
$ret = array();
foreach ($a as $k) {
unset($t);
if (preg_match('/^(.*)\((.*)\)$/', $k, $m)) {
$k = $m[1];
$t = $m[2];
}
if (!isset($dd[$k]))
bark("dictionary is missing key(s)");
if (isset($t)) {
if ($dd[$k]["type"] != $t)
bark("invalid entry in dictionary");
$ret[] = $dd[$k]["value"];
}
else
$ret[] = $dd[$k];
}
return $ret;
}
function dict_get($d, $k, $t) {
if ($d["type"] != "dictionary")
bark("not a dictionary");
$dd = $d["value"];
if (!isset($dd[$k]))
return;
$v = $dd[$k];
if ($v["type"] != $t)
bark("invalid dictionary entry type");
return $v["value"];
}
list($ann, $info) = dict_check($dict, "announce(string):info");
list($dname, $plen, $pieces) = dict_check($info, "name(string):piece length(integer):pieces(string)");
if (!in_array($ann, $announce_urls, 1))
bark("invalid announce url! must be <b>" . $announce_urls[0] . "</b>");
if (strlen($pieces) % 20 != 0)
bark("invalid pieces");
$filelist = array();
$totallen = dict_get($info, "length", "integer");
if (isset($totallen)) {
$filelist[] = array($dname, $totallen);
$type = "single";
}
else {
$flist = dict_get($info, "files", "list");
if (!isset($flist))
bark("missing both length and files");
if (!count($flist))
bark("no files");
$totallen = 0;
foreach ($flist as $fn) {
list($ll, $ff) = dict_check($fn, "length(integer):path(list)");
$totallen += $ll;
$ffa = array();
foreach ($ff as $ffe) {
if ($ffe["type"] != "string")
bark("filename error");
$ffa[] = $ffe["value"];
}
if (!count($ffa))
bark("filename error");
$ffe = implode("/", $ffa);
$filelist[] = array($ffe, $ll);
}
$type = "multi";
}
$infohash = pack("H*", sha1($info["string"]));
// Replace punctuation characters with spaces
$torrent = str_replace("_", " ", $torrent);
$nfo = sqlesc(str_replace("\x0d\x0d\x0a", "\x0d\x0a", @file_get_contents($nfofilename)));
$ret = mysql_query("INSERT INTO torrents (search_text, filename, owner, visible, info_hash, name, size, numfiles, type, descr, ori_descr, category, save_as, added, last_action, nfo) VALUES (" .
implode(",", array_map("sqlesc", array(searchfield("$shortfname $dname $torrent"), $fname, $CURUSER["id"], "no", $infohash, $torrent, $totallen, count($filelist), $type, $descr, $descr, 0 + $_POST["type"], $dname))) .
", '" . get_date_time() . "', '" . get_date_time() . "', $nfo)");
if (!$ret) {
if (mysql_errno() == 1062)
bark("torrent already uploaded!");
bark("mysql puked: ".mysql_error());
}
$id = mysql_insert_id();
@mysql_query("DELETE FROM files WHERE torrent = $id");
foreach ($filelist as $file) {
@mysql_query("INSERT INTO files (torrent, filename, size) VALUES ($id, ".sqlesc($file[0]).",".$file[1].")");
}
move_uploaded_file($tmpname, "$torrent_dir/$id.torrent");
write_log("Torrent $id ($torrent) was uploaded by " . $CURUSER["username"]);
header("Location : $BASEURL/details.php?id=$id&uploaded=1");
hit_end();
?>
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
|
|
|
|
|
« Reply to dl problems
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|