Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: php upload a 600 chmod
Forum PHP.pl > Forum > PHP
byczek
Witam mam problem z skryptem uploadu a mianowicie zapisuje mi pliki z chmod 600 czy da sie to jakos zmienic? ponirzej jest kod pliku jesli ktos wie moze mog³by mi go poprawic:)
  1. <?
  2.  
  3. require_once("include/benc.php");
  4. require_once("include/bittorrent.php");
  5. require "rconpasswords.php";
  6.  
  7. hit_start();
  8.  
  9. ini_set("upload_max_filesize",$max_torrent_size);
  10.  
  11. function bark($msg) {
  12. genbark($msg, "Upload failed!");
  13. }
  14.  
  15. dbconn(); 
  16.  
  17. hit_count();
  18.  
  19. loggedinorreturn();
  20. /*
  21. if (get_user_class() < UC_UPLOADER)
  22.   die;
  23. */
  24. foreach(explode(":","descr:type:name") as $v) {
  25. if (!isset($_POST[$v]))
  26. bark("missing form data");
  27. }
  28.  
  29. if (!isset($_FILES["file"]))
  30. bark("missing form data");
  31.  
  32. $f = $_FILES["file"];
  33. $fname = unesc($f["name"]);
  34. if (empty($fname))
  35. bark("Empty filename!");
  36. /*
  37. $nfofile = $_FILES['nfo'];
  38. if ($nfofile['name'] == '')
  39.   bark("No NFO!");
  40.  
  41. if ($nfofile['size'] == 0)
  42.   bark("0-byte NFO");
  43.  
  44. if ($nfofile['size'] > 65535)
  45.   bark("NFO is too big! Max 65,535 bytes.");
  46.  
  47. $nfofilename = $nfofile['tmp_name'];
  48.  
  49. if (@!is_uploaded_file($nfofilename))
  50.   bark("NFO upload failed");
  51. */
  52. $descr = unesc($_POST["descr"]);
  53. if (!$descr)
  54. bark("You must enter a description!");
  55.  
  56. $catid = (+ $_POST["type"]);
  57. if (!is_valid_id($catid))
  58. bark("You must select a category to put the torrent in!");
  59.  
  60. if (!validfilename($fname))
  61. bark("Invalid filename!");
  62. if (!preg_match('/^(.+).torrent$/si', $fname, $matches))
  63. bark("Invalid filename (not a .torrent).");
  64. $shortfname = $torrent = $matches[1];
  65. if (!empty($_POST["name"]))
  66. $torrent = unesc($_POST["name"]);
  67.  
  68. $tmpname = $f["tmp_name"];
  69. if (!is_uploaded_file($tmpname))
  70. bark("eek");
  71. if (!filesize($tmpname))
  72. bark("Empty file!");
  73.  
  74. $dict = bdec_file($tmpname, $max_torrent_size);
  75. if (!isset($dict))
  76. bark("What the hell did you upload? This is not a bencoded file!");
  77.  
  78. function dict_check($d, $s) {
  79. if ($d["type"] != "dictionary")
  80. bark("not a dictionary");
  81. $a = explode(":", $s);
  82. $dd = $d["value"];
  83. $ret = array();
  84. foreach ($a as $k) {
  85. unset($t);
  86. if (preg_match('/^(.*)((.*))$/', $k, $m)) {
  87. $k = $m[1];
  88. $t = $m[2];
  89. }
  90. if (!isset($dd[$k]))
  91. bark("dictionary is missing key(s)");
  92. if (isset($t)) {
  93. if ($dd[$k]["type"] != $t)
  94. bark("invalid entry in dictionary");
  95. $ret[] = $dd[$k]["value"];
  96. }
  97. else
  98. $ret[] = $dd[$k];
  99. }
  100. return $ret;
  101. }
  102.  
  103. function dict_get($d, $k, $t) {
  104. if ($d["type"] != "dictionary")
  105. bark("not a dictionary");
  106. $dd = $d["value"];
  107. if (!isset($dd[$k]))
  108. return;
  109. $v = $dd[$k];
  110. if ($v["type"] != $t)
  111. bark("invalid dictionary entry type");
  112. return $v["value"];
  113. }
  114.  
  115. list($ann, $info) = dict_check($dict, "announce(string):info");
  116. list($dname, $plen, $pieces) = dict_check($info, "name(string):piece length(integer):pieces(string)");
  117. /*
  118. if (!in_array($ann, $announce_urls, 1))
  119. bark("Sory ale po³ykam tylko torrenty na moim trackerze przezucac z innych stron 
    niestety nie mozna :( <b>" . $announce_urls[0] . "</b>");
  120.  
  121. */
  122. if (strlen($pieces) % 20 != 0)
  123. bark("invalid pieces");
  124.  
  125. $filelist = array();
  126. $totallen = dict_get($info, "length", "integer");
  127. if (isset($totallen)) {
  128. $filelist[] = array($dname, $totallen);
  129. $type = "single";
  130. }
  131. else {
  132. $flist = dict_get($info, "files", "list");
  133. if (!isset($flist))
  134. bark("missing both length and files");
  135. if (!count($flist))
  136. bark("no files");
  137. $totallen = 0;
  138. foreach ($flist as $fn) {
  139. list($ll, $ff) = dict_check($fn, "length(integer):path(list)");
  140. $totallen += $ll;
  141. $ffa = array();
  142. foreach ($ff as $ffe) {
  143. if ($ffe["type"] != "string")
  144. bark("filename error");
  145. $ffa[] = $ffe["value"];
  146. }
  147. if (!count($ffa))
  148. bark("filename error");
  149. $ffe = implode("/", $ffa);
  150. $filelist[] = array($ffe, $ll);
  151. }
  152. $type = "multi";
  153. }
  154.  
  155. $infohash = pack("H*", sha1($info["string"]));
  156. // Replace punctuation characters with spaces
  157.  
  158.  
  159. $torrent = str_replace("_", " ", $torrent);
  160.  
  161. $html = $_POST["html"];
  162. $nfofile = $_FILES['nfo'];
  163. if ($nfofile['size'] > 65535)
  164. bark("NFO is too big! Max 65,535 bytes.");
  165. $nfofilename = $nfofile['tmp_name'];
  166. if (@is_uploaded_file($nfofilename) && @filesize($nfofilename) > 0)
  167. $nfo = sqlesc(str_replace("x0dx0dx0a", "x0dx0a", file_get_contents($nfofilename)));
  168. else
  169. $nfo = "''";
  170. $img=$_FILES['img']['name'];
  171. $ret = mysql_query("INSERT INTO torrents (search_text, filename, owner, visible, info_hash, name, size, numfiles, typ
    e, descr, ori_descr, category, save_as, added, last_action, nfo, image) VALUES ("
     .
  172. implode(",", array_map("sqlesc", array(searchfield("$shortfname $dname $torrent"), $fname, $CURUSER["id"], "no", $infohash, $torrent, $totallen, count($filelist), $type, parsedescr($descr, $html), $descr, 0 + $_POST["type"], $dname))) .
  173. ", '" . get_date_time() . "', '" . get_date_time() . "', $nfo, '$img' )");
  174. if (!$ret) {
  175. if (mysql_errno() == 1062)
  176. bark("torrent already uploaded!");
  177. bark("mysql puked: ".mysql_error());
  178. }
  179. $id = mysql_insert_id();
  180.  
  181. @mysql_query("DELETE FROM files WHERE torrent = $id");
  182. foreach ($filelist as $file) {
  183. @mysql_query("INSERT INTO files (torrent, filename, size) VALUES ($id, ".sqlesc($file[0]).",".$file[1].")");
  184. }
  185.  
  186. move_uploaded_file($tmpname, "$torrent_dir/$id.torrent");
  187.  
  188. $img=$_FILES['img']['name'];
  189. $imgtmp=$_FILES['img']['tmp_name'];
  190. move_uploaded_file($imgtmp,"images/$img");
  191.  
  192. write_log("Torrent $id ($torrent) was uploaded by " . $CURUSER["username"]);
  193.  
  194.  
  195. /* Game server notif */
  196.  
  197. $f = fsockopen("udp://62.212.84.221", 28960);
  198. fwrite($f, "xFFxFFxFFxFFrcon $rconpassword say Torrent uploaded: $torrentn");
  199. fread($f, 8192);
  200. fclose($f);
  201.  
  202.  
  203.  
  204. /* RSS feeds */
  205.  
  206. if (($fd1 = @fopen("rss.xml", "w")) && ($fd2 = fopen("rssdd.xml", "w")))
  207. {
  208. $cats = "";
  209. $res = mysql_query("SELECT id, name FROM categories");
  210. while ($arr = mysql_fetch_assoc($res))
  211. $cats[$arr["id"]] = $arr["name"];
  212. $s = "<?xml version="1.0" encoding="iso-8859-1" ?>n<rss version="0.91">n<channel>n" .
  213. "<title>TorrentBits</title>n<description>0-week torrents</description>n<link>$DEFAULTBASEURL/</link>n";
  214. @fwrite($fd1, $s);
  215. @fwrite($fd2, $s);
  216. $r = mysql_query("SELECT id,name,descr,filename,category FROM torrents ORDER BY added DESC LI
    MIT 15"
    ) or sqlerr(__FILE__, __LINE__);
  217. while ($a = mysql_fetch_assoc($r))
  218. {
  219. $cat = $cats[$a["category"]];
  220. $s = "<item>n<title>" . htmlspecialchars($a["name"] . " ($cat)") . "</title>n" .
  221. "<description>" . htmlspecialchars($a["descr"]) . "</description>n";
  222. @fwrite($fd1, $s);
  223. @fwrite($fd2, $s);
  224. @fwrite($fd1, "<link>$DEFAULTBASEURL/details.php?id=$a[id]&amp;hit=1</link>n</item>n");
  225. $filename = htmlspecialchars($a["filename"]);
  226. @fwrite($fd2, "<link>$DEFAULTBASEURL/download/$a[id]/$filename</link>n</item>n");
  227. }
  228. $s = "</channel>n</rss>n";
  229. @fwrite($fd1, $s);
  230. @fwrite($fd2, $s);
  231. @fclose($fd1);
  232. @fclose($fd2);
  233. }
  234.  
  235. /* Email notifs */
  236. /*******************
  237.  
  238. $res = mysql_query("SELECT name FROM categories WHERE id=$catid") or sqlerr();
  239. $arr = mysql_fetch_assoc($res);
  240. $cat = $arr["name"];
  241. $res = mysql_query("SELECT email FROM users WHERE enabled='yes' AND notifs LIKE '%[cat$catid]%'") or sqlerr();
  242. $uploader = $CURUSER['username'];
  243.  
  244. $size = mksize($totallen);
  245. $description = ($html ? strip_tags($descr) : $descr);
  246.  
  247. $body = <<<EOD
  248. A new torrent has been uploaded.
  249.  
  250. Name: $torrent
  251. Size: $size
  252. Category: $cat
  253. Uploaded by: $uploader
  254.  
  255. Description
  256. -------------------------------------------------------------------------------
  257. $description
  258. -------------------------------------------------------------------------------
  259.  
  260. You can use the URL below to download the torrent (you may have to login).
  261.  
  262. $DEFAULTBASEURL/details.php?id=$id&hit=1
  263.  
  264. -- 
  265. $SITENAME
  266. EOD;
  267. $to = "";
  268. $nmax = 100; // Max recipients per message
  269. $nthis = 0;
  270. $ntotal = 0;
  271. $total = mysql_num_rows($res);
  272. while ($arr = mysql_fetch_row($res))
  273. {
  274.   if ($nthis == 0)
  275. $to = $arr[0];
  276.   else
  277. $to .= "," . $arr[0];
  278.   ++$nthis;
  279.   ++$ntotal;
  280.   if ($nthis == $nmax || $ntotal == $total)
  281.   {
  282. if (!mail("Multiple recipients <$SITEEMAIL>", "New torrent - $torrent", $body,
  283. "From: $SITEEMAILrnBcc: $to", "-f$SITEEMAIL"))
  284.    stderr("Error", "Your torrent has been been uploaded. DO NOT RELOAD THE PAGE!n" .
  285.  "There was however a problem delivering the e-mail notifcations.n" .
  286.  "Please let an administrator know about this error!n");
  287. $nthis = 0;
  288.   }
  289. }
  290. *******************/
  291.  
  292. header("Location: $DEFAULTBASEURL/details.php?id=$id&uploaded=1");
  293.  
  294. hit_end();
  295.  
  296. ?>


---

tiraeth
Kicok
chmod() na zuploadowanych plikach?
byczek
Cytat(Kicok @ 2005-09-20 17:05:19)
chmod() na zuploadowanych plikach?

Tak sad.gif
nospor
http://forum.php.pl/index.php?showtopic=35434 - crossposting (Regulamin IV.2, podpunkt f) )
Zamykam.
To jest wersja lo-fi g³ównej zawarto¶ci. Aby zobaczyæ pe³n± wersjê z wiêksz± zawarto¶ci±, obrazkami i formatowaniem proszê kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.