Jamdog Posted May 16, 2012 Share Posted May 16, 2012 To give some background, I'm currently working on a private site that allows members access to large document files via a torrent system. Now, this is the PHP code I have: $id = $_REQUEST['id']; if (!$id) httperr(); $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(); $fs = filesize($fn); $tor_fname = $row["filename"]; mysql_query("UPDATE torrents SET hits = hits + 1 WHERE id = $id"); require_once "include/benc.php"; // Torrent Encoding Functions $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']); header("Content-Type: application/x-bittorrent"); header("Content-Disposition: attachment; filename=\"" . basename($tor_fname) . "\"" ); print(benc($dict)); This is taken from (and is the majority of) the file download.php. This is called like: download.php?id=?? The above should work, but when I use it, it tries to save the file as download.torrent, even though the $tor_fname variable doesn't contain that value. I'd obviously like to force the filename to be '<filename>.torrent' rather than the same name as the php script with .torrent on the end. Any ideas? Am I doing something stupid, or is there some way of doing this? Quote Link to comment https://forums.phpfreaks.com/topic/262610-download-script-not-working/ Share on other sites More sharing options...
trq Posted May 16, 2012 Share Posted May 16, 2012 You don't select any field from the database called "filename". Quote Link to comment https://forums.phpfreaks.com/topic/262610-download-script-not-working/#findComment-1345936 Share on other sites More sharing options...
Jamdog Posted May 16, 2012 Author Share Posted May 16, 2012 Now having a 'Doh!' moment! Thanks Thorpe, that fixed it! Quote Link to comment https://forums.phpfreaks.com/topic/262610-download-script-not-working/#findComment-1345938 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.