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
https://forums.phpfreaks.com/topic/262610-download-script-not-working/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.