Jump to content

Download script not working


Jamdog

Recommended Posts

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.