Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
Files in description!
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / General / General Chat

2021-06-05 10:15:14
hello i wont to import some torrents so they have no description
and i wont all the files from torrent to be added in descr table

$descr = str_replace(".torrent","",$name); >??>>??

<?php
//
require_once("backend/functions.php");
dbconn();

$dir = "import";

//ini_set("upload_max_filesize",$max_torrent_size);

$files = array();
$dh = opendir("$dir/");
while (false !== ($file=readdir($dh))) {
if (preg_match("/\.torrent$/i", $file))
$files[] = $file;
}
closedir($dh);


// check access and rights
if ($CURUSER["edit_torrents"] != "yes")
show_error_msg(T_("ERROR"), T_("ACCESS_DENIED"), 1);

$announce_urls = explode(",", strtolower($site_config["announce_list"]));  //generate announce_urls[] from config.php

if ($takeupload == "yes") {
set_time_limit(0);
require_once("backend/parse.php");
stdhead(T_("UPLOAD_COMPLETE"));
begin_frame(T_("UPLOAD_COMPLETE"));
echo "<center>";

//check form data
$catid = (int)$_POST["type"];

if (!is_valid_id($catid))
$message = T_("UPLOAD_NO_CAT");

if (empty($message)) {
$r = mysql_query("SELECT name, parent_cat FROM categories WHERE id=$catid");
$r = mysql_fetch_row($r);

echo "<b>Category:</B> ".htmlspecialchars($r[1])." -> ".htmlspecialchars($r[0])."<BR>";
for ($i=0;$i<count($files);$i++) {
$fname = $files[$i];



$langid = (int)$_POST["lang"];

preg_match('/^(.+)\.torrent$/si', $fname, $matches);
$shortfname = $torrent = $matches[1];

//parse torrent file
$torrent_dir = $site_config["torrent_dir"];

$TorrentInfo = array();
$TorrentInfo = ParseTorrent("$dir/$fname");
$announce = strtolower($TorrentInfo[0]);
$infohash = $TorrentInfo[1];
$creationdate = $TorrentInfo[2];
$internalname = $TorrentInfo[3];
$torrentsize = $TorrentInfo[4];
$filecount = $TorrentInfo[5];
$annlist = $TorrentInfo[6];
$comment = $TorrentInfo[7];
$filelist = $TorrentInfo[8];

$message = "<BR><BR><HR><BR><b>$internalname</B><BR><BR>fname: ".htmlspecialchars($fname)."<BR>message:$filelist";

//check announce url is local or external
if (!in_array($announce, $announce_urls, 1))
$external='yes';
else
$external='no';

if (!$site_config["ALLOWEXTERNAL"] && $external == 'yes') {
$message .= T_("UPLOAD_NO_TRACKER_ANNOUNCE");
echo $message;
continue;
}

$name = $internalname;
$name = str_replace(".torrent","",$name);
$name = str_replace("_", " ", $name);
           $descr = str_replace(".torrent","",$name);

//anonymous upload
$anonyupload = $_POST["anonycheck"];
if ($anonyupload == "yes")
$anon = "yes";
else
$anon = "no";

$ret = mysql_query("INSERT INTO torrents (filename, owner, name, descr, image1, image2, category, added, info_hash, size, numfiles, save_as, announce, external, nfo, torrentlang, anon) VALUES (".sqlesc($fname).", '".$CURUSER['id']."', ".sqlesc($name).", ".sqlesc($descr).", '".$inames[0]."', '".$inames[1]."', '".catid."', '" . get_date_time() . "', '".$infohash."', '".$torrentsize."', '".$filecount."', ".sqlesc($fname).", '".$announce."', '".$external."', '".$nfo."', '".$langid."','$anon')");

$id = mysql_insert_id();

if (mysql_errno() == 1062) {
$message .= T_("UPLOAD_ALREADY_UPLOADED");
echo $message;
continue;
}

if($id == 0){
$message .= T_("UPLOAD_NO_ID");
echo $message;
continue;
}
   
copy("$dir/$files[$i]", "uploads/$id.torrent");
if (count($filelist)) {
       foreach ($filelist as $file) {
           $dir = '';
           $size = $file["length"];
           $count = count($file["path"]);
           for ($i = 0; $i < $count; $i++) {
               if (($i + 1) == $count)
                   $fname = $dir . $file["path"][$i];
               else
                   $dir .= $file["path"][$i] . "/";
           }
           mysql_query("INSERT INTO `files` (`torrent`, `path`, `filesize`) VALUES($id, " . sqlesc($fname) . ", $size)");
       }
   } else {
       mysql_query("INSERT INTO `files` (`torrent`, `path`, `filesize`) VALUES($id, " . sqlesc($TorrentInfo[3]) . ", $torrentsize)");
   }
//EXTERNAL SCRAPE
if ($external == "yes") {
$tracker=str_replace("/announce","/scrape",$announce);
$stats = torrent_scrape_url($tracker, $infohash);
$seeders = strip_tags($stats['seeds']);
$leechers = strip_tags($stats['peers']);
$downloaded = strip_tags($stats['downloaded']);

mysql_query("UPDATE torrents SET leechers='".$leechers."', seeders='".$seeders."',times_completed='".$downloaded."',last_action= '".get_date_time()."',visible='yes' WHERE id='".$id."'");
}
//END SCRAPE

write_log("Torrent $id ($name) was Uploaded by $CURUSER[username]");

$message .= "<BR><b>".T_("UPLOAD_OK")."</B><BR><a href=file.php?id=".$id.">".T_("UPLOAD_VIEW_DL")."</a><BR><BR>";
echo $message;
@unlink("$dir/$fname");
}
echo "</center>";
end_frame();
stdfoot();
die;
}else
show_error_msg(T_("UPLOAD_FAILED"), $message, 1);

}//takeupload


///////////////////// FORMAT PAGE ////////////////////////

stdhead(T_("UPLOAD"));

begin_frame(T_("UPLOAD"));
?>
<form name="upload" enctype="multipart/form-data" action="torrents-import.php" method="post">
<input type="hidden" name="takeupload" value="yes" />
<table border="0" class="xty" cellspacing="0" cellpadding="6" width="1130px" align="center">
<TR><TD align=right valign=top><b>Description:</B></TD><TD align=left><?php
if (!count($files))
echo T_("NOTHING_TO_SHOW_FILES")." $dir/.";
else{
foreach ($files as $f)
echo htmlspecialchars($f)."<BR>";
echo "<BR>Total files: ".count($files);
}?></TD></TR>
<?php
$category = "<select name=\"type\">\n<option value=\"0\">" . T_("CHOOSE_ONE") . "</option>\n";

$cats = genrelist();
foreach ($cats as $row)
$category .= "<option value=\"" . $row["id"] . "\">" . htmlspecialchars($row["parent_cat"]) . ": " . htmlspecialchars($row["name"]) . "</option>\n";

$category .= "</select>\n";
print ("<TR><TD align=right>" .T_("CATEGORY"). ": </td><td align=left>".$category."</td></tr>");


$language = "<select name=\"lang\">\n<option value=\"0\">Unknown/NA</option>\n";

$langs = langlist();
foreach ($langs as $row)
$language .= "<option value=\"" . $row["id"] . "\">" . htmlspecialchars($row["name"]) . "</option>\n";

$language .= "</select>\n";
print ("<TR><TD align=right>Language: </td><td align=left>".$language."</td></tr>");

if ($site_config['ANONYMOUSUPLOAD']){ ?>
<TR><TD align=right><?php echo T_("UPLOAD_ANONY");?>: </td><td><?php printf("<input name=anonycheck value=yes type=radio" . ($anonycheck ? " checked" : "") . ">Yes <input name=anonycheck value=no type=radio" . (!$anonycheck ? " checked" : "") . ">No"); ?> &nbsp;<I><?php echo T_("UPLOAD_ANONY_MSG");?></font>
</td></tr>

<?php } ?>
<TR><TD align=center colspan=2><input type="submit" value="<?php echo T_("UPLOAD")?>"><BR>
<I><?php echo T_("CLICK_ONCE_IMAGE");?></I></form></TD></TR></TABLE>
<?php
end_frame();
stdfoot();
?>
2021-06-06 19:21:45
maybe this can get you on the path to accomplishing what you need. Im just taking a guess at this since I havent tested it
		 if ($row["descr"]=='No description given.'){
SQL_Query_exec("UPDATE `torrents` SET `descr` = '".mysql_real_escape_string ($filelist). "' WHERE `id` = $id");
}

or maybe if you dont have SQL_Query_exec
		 if ($row["descr"]=='No description given.'){
mysql_query("UPDATE `torrents` SET `descr` = '".mysql_real_escape_string ($filelist). "' WHERE `id` = $id");
}


Maybe add this code to torrents-details.php
TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
Last edited by MicroMonkey on 2021-06-06 19:25:21
2021-06-07 14:11:03
I had a look as well and I agree with micromonkey this seems easiest way

mysql_query("UPDATE `torrents` SET `descr` = '".mysql_real_escape_string ($filelist). "' WHERE `id` = $id";);


I would try placing just query at bottom of torrents-upload or torrents-import.
It looks like on import $filelist is a array so not sure how it would look or might even throw a error.

Might need to change array to string and preg replace ? ,  for appearance

Maybe try this if you get error
$filesindesc = implode(", ", $filelist);
mysql_query("UPDATE `torrents` SET `descr` = '".mysql_real_escape_string ($filesindesc). "' WHERE `id` = $id";);

Last edited by M-jay warn on 2021-06-07 15:12:24
2021-06-07 19:14:23
THX ALL FOR RESPOND !!!

:thumb  :thumb  :thumb  :thumb  :thumb  :thumb  :thumb  :thumb
Last edited by M-jay warn on 2021-06-09 13:39:07
2021-06-09 00:05:18
implode() is the way.
Additionally, in the reverse situation in SQL to delimitate results you do this

GROUP_CONCAT(ids)

and to read them off (in another query) is IN(, , ,)

Example:

$var1 = SELECT GROUP_CONCAT(user.id) FROM users

$myarray1 = [];
foreach ($var1 as $row) {
  $var2 = SELECT username, id, avatar FROM users WHERE id IN($row[id])
  // Now you get results for each user ID easily. No JOINs, no extra code.
  // How to push the data out and work with it? array_push(), but there are many ways.
  // Array push allows you push all of your looped results outside of the loop, so you can
  // access it later.
  $data['id']  =  $row['id'];
  array_push($myarray1, $data);
}

There is more, like appending a query and fetch as a data item, and pushing that array out in itself, and merging results, you can push $var2 into a array (or JSON) and work with both result sets side by side, merge, modify, filter..

Is database column empty??
if (empty($row['xyz']))

$var = !empty($row['xyz']) ? $row['xyz'] : 'Column looks empty!'


So you know what implode does. Explode does the opposite, and is usually called from outside of foreach() as it allows to iterate each comma separated result.

If you just want to call on a specific index from the array, use like this explode()[3]
where "5" is the 5th result you want to capture (excluding the rest).  - (1, 2, 3, 4, 5)

I'll try to answer where I can. It helps to understand arrays, the typical functions for most cases and knowing the little tips and "one-liner" solutions.
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 2
  • Members: 0
  • Guests online: 2
  • Comments: 3
  • Messages: 1,728