PageRenderTime 26ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/uploads/upload.php

https://github.com/AndyRixon/LayerBulletin
PHP | 411 lines | 323 code | 67 blank | 21 comment | 21 complexity | 390307f805407b5057fe9dbeb024a16b MD5 | raw file
  1. <?php
  2. /*
  3. +--------------------------------------------------------------------------
  4. | LayerBulletin
  5. | ========================================
  6. | By The LayerBulletin team
  7. | Released under the Artistic License 2.0
  8. | http://layerbulletin.com/
  9. | ========================================
  10. |+--------------------------------------------------------------------------
  11. | upload.php - Shows avatar & attachment upload forms.
  12. */
  13. define("LB_RUN", 1);
  14. error_reporting(0);
  15. // Best to include the config file..
  16. include "../includes/config.php";
  17. include "../scripts/php/functions.php";
  18. $my_address="http://".$_SERVER['HTTP_HOST']."".$_SERVER['PHP_SELF'];
  19. $lb_domain = str_replace('/uploads/upload.php', '', $my_address); // returns http://myforum.com/forum style address
  20. global $db_prefix;
  21. if (isset($_COOKIE['lb_name'])){
  22. $lb_name = escape_string($_COOKIE['lb_name']);
  23. $lb_name = str_replace("'", "", $lb_name);
  24. if (!preg_match('|^[a-zA-Z0-9!@#$%^&*();:_.\\\\ /\t-]+$|', $lb_name) ) {
  25. setcookie("lb_name", $name, time() -1);
  26. setcookie("lb_password", $password, time() -1);
  27. lb_redirect("index.php?page=error&error=32","error/32");
  28. }
  29. $lb_password=$_COOKIE['lb_password'];
  30. $lb_password=escape_string($lb_password);
  31. }
  32. // if the user is logged in, let's get their ID, and if that doesn't work, return an error....
  33. $query211 = "select ID, BANNED from {$db_prefix}members WHERE name='$lb_name' AND password='$lb_password'" ;
  34. $result211 = mysql_query($query211) or die("Query failed");
  35. $id_count = mysql_num_rows($result211);
  36. while ($results211 = mysql_fetch_array($result211)){
  37. $my_id = $results211['ID'];
  38. $banned = $results211['BANNED'];
  39. }
  40. if ($my_id < '1' OR $banned=='1' OR !isset($lb_name) OR $id_count!='1'){
  41. echo "You can't upload files without being logged in.";
  42. exit();
  43. }
  44. $query_theme = "select THEME, BOARD_LANG, ATTACH_AVATAR_SIZE from {$db_prefix}settings" ;
  45. $result_theme = mysql_query($query_theme) or die("Query failed") ;
  46. while ($results_theme = mysql_fetch_array($result_theme)){
  47. $theme = $results_theme['THEME'];
  48. $board_lang = $results_theme['BOARD_LANG'];
  49. $attach_avatar_size = $results_theme['ATTACH_AVATAR_SIZE'];
  50. }
  51. if (isset($_COOKIE['lb_theme'])){
  52. $member_selected_theme=escape_string($_COOKIE['lb_theme']);
  53. }
  54. $query_theme = "select THEME from {$db_prefix}members WHERE NAME='$lb_name'" ;
  55. $result_theme = mysql_query($query_theme) or die("structure.php - Error in query: $query_theme") ;
  56. $member_selected_theme = mysql_result($result_theme, 0);
  57. // check theme is available to use,,,,
  58. $query_theme = "select THEME_NAME from {$db_prefix}themes WHERE THEME_NAME='$member_selected_theme'" ;
  59. $result_theme = mysql_query($query_theme) or die("structure.php - Error in query: $query_theme") ;
  60. $check_theme = mysql_num_rows($result_theme);
  61. if ($check_theme!='0' && $member_selected_theme!=''){
  62. $theme = $member_selected_theme;
  63. }
  64. $topicid = escape_string($_GET['topicid']);
  65. $attachtype=escape_string($_GET['attachtype']);
  66. $hash=escape_string($_GET['hash']);
  67. // and the images
  68. include "../scripts/php/image_check.php";
  69. $get_id=escape_string($_GET['member']);
  70. $query_member_stuff = "select BOARD_LANG from {$db_prefix}members WHERE ID ='$get_id'" ;
  71. $result_member_stuff = mysql_query($query_member_stuff) or die("header.php - Error in query: $query_member_stuff") ;
  72. $secure = mysql_num_rows ($result_member_stuff);
  73. if ($secure!='0'){
  74. $member_lang = mysql_result($result_member_stuff, 0);
  75. }
  76. echo "<html style='overflow: hidden; border: none;'>";
  77. echo "<head>";
  78. if (!isset($board_lang)){
  79. $board_lang="english_en";
  80. }
  81. else{
  82. $board_lang="english_en";
  83. }
  84. if (isset($member_lang) && $member_lang!=''){
  85. $board_lang="$member_lang";
  86. }
  87. // Do you speekee english?
  88. if (isset($_COOKIE['lb_lang']) && (!isset($_COOKIE['lb_name']))){
  89. $board_lang = escape_string($_COOKIE['lb_lang']);
  90. if (!file_exists("../lang/$board_lang/lang_forum.php")){
  91. $board_lang = "english_en";
  92. }
  93. }
  94. // include the language...
  95. include "../lang/$board_lang/lang_forum.php";
  96. ?>
  97. <!-- Set Javascript function to make animation appear onsubmit -->
  98. <script type="text/javascript">
  99. function form_submit() {
  100. var load = document.getElementById('loadbg');
  101. //document.form1.submit();
  102. load.style.display = 'block';
  103. load.src = '<?php echo $working_img; ?>';
  104. }
  105. </script>
  106. <?php
  107. if ($theme!='layerbulletin_default'){
  108. echo "<link rel='stylesheet' href='$lb_domain/themes/layerbulletin_default/stylesheet.css' type='text/css'>";
  109. }
  110. echo "<link rel='stylesheet' href='$lb_domain/themes/$theme/stylesheet.css' type='text/css'>";
  111. echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
  112. echo "</head>";
  113. echo "<body style='overflow: hidden; margin: 0px;'>";
  114. echo "<div class='upload'>";
  115. $attachtype=escape_string($_GET['attachtype']);
  116. if (isset($_GET['id'])){
  117. // Delete the attachment, then return form back to start..
  118. $lb_name=$_COOKIE['lb_name'];
  119. $lb_password=$_COOKIE['lb_password'];
  120. $lb_name=escape_string($lb_name);
  121. $lb_password=escape_string($lb_password);
  122. // if the user is logged in, let's get their ID, and if that doesn't work, return an error....
  123. $query211 = "select ID from {$db_prefix}members WHERE name='$lb_name' AND password='$lb_password'" ;
  124. $result211 = mysql_query($query211) or die("Query failed") ;
  125. $member = mysql_result($result211, 0);
  126. $id=$_GET['id'];
  127. $id=escape_string($id);
  128. $query2121 = "select FILENAME from {$db_prefix}attachments WHERE ROW='$id'" ;
  129. $result2121 = mysql_query($query2121) or die("upload.php - Error in query: $query2121") ;
  130. while ($results2121 = mysql_fetch_array($result2121)){
  131. $filename = $results2121['FILENAME'];
  132. foreach (glob("attachments/$filename") as $filename_original) {
  133. unlink($filename_original);
  134. }
  135. foreach (glob("attachments/t_$filename") as $filename_thumb) {
  136. unlink($filename_thumb);
  137. }
  138. }
  139. mysql_query("DELETE FROM {$db_prefix}attachments WHERE row ='$id'");
  140. echo "<meta http-equiv=\"refresh\" content=\"0;url=$lb_domain/uploads/upload.php?topicid=$topicid&attachtype=$attachtype&hash=$hash\" />";
  141. echo "</div>";
  142. }
  143. else{
  144. /*
  145. Get user's id
  146. */
  147. $query = mysql_query('SELECT id FROM ' . $db_prefix . 'members WHERE name = "' . $lb_name . '" AND password = "' . $lb_password . '"');
  148. $result = mysql_fetch_assoc($query);
  149. $member = $result['id'];
  150. // if they uploaded, they'll have been redirected back here,
  151. // so obviously they uploaded already!
  152. // Let's show their file info here...
  153. echo "<form method='post' name='form1' action='upload.php'>";
  154. // if this is an avatar, show avatar :)
  155. if ($_GET['attachtype']=='avatar'){
  156. // Grab member info...
  157. $query211 = "select AVATAR, REMOTE_AVATAR from {$db_prefix}members WHERE ID='$member'" ;
  158. $result211 = mysql_query($query211) or die("Query failed");
  159. $avatar_check = mysql_num_rows($result211);
  160. if ($avatar_check!='0'){
  161. while ($results211 = mysql_fetch_array($result211)){
  162. $avatar = $results211['AVATAR'];
  163. $remote_avatar = $results211['REMOTE_AVATAR'];
  164. if ($remote_avatar =='0'){
  165. $avatar = $lb_domain."/".$avatar;
  166. }
  167. }
  168. }
  169. else{
  170. $avatar="";
  171. }
  172. if ($avatar=='' OR $avatar==$lb_domain){
  173. $avatar = $default_avatar;
  174. }
  175. echo "<div class='center'><img style='max-width: $attach_avatar_size;' src='$avatar' alt='' /><br /><br /></div>";
  176. }
  177. if ($_GET['attachtype']=='avatar'){
  178. }
  179. else{
  180. ?>
  181. <div style="width: 50%; float: left; text-align: left;">
  182. <select name="fileselect" onchange="form_submit(); location.href='<?php echo "$lb_domain"; ?>/uploads/upload.php?&downloadselect=1&topicid=<?php echo "$topicid"; ?>&attachtype=<?php echo "$attachtype"; ?>&member=<?php echo "$member"; ?>&hash=<?php echo "$hash"; ?>&id='+escape(this.options[this.selectedIndex].value)">
  183. <?php
  184. echo "<option value=''>".$lang['upload_option']."</option>";
  185. $query211 = "select ORIGINAL_FILENAME, FILESIZE, ROW from {$db_prefix}attachments WHERE hash='$hash' ORDER BY ORIGINAL_FILENAME desc" ;
  186. $result211 = mysql_query($query211) or die("Query failed2") ;
  187. while ($results211 = mysql_fetch_array($result211)){
  188. $original_filename = $results211['ORIGINAL_FILENAME'];
  189. $row = $results211['ROW'];
  190. $filesize = $results211['FILESIZE'];
  191. if ($filesize < 1024){
  192. $filesize = "$filesize bytes";
  193. }
  194. elseif ($filesize < 1048576){
  195. $filesize = $filesize/1024;
  196. $filesize = round($filesize,2);
  197. $filesize = $filesize."kb";
  198. }
  199. else{
  200. $filesize = $filesize/1048576;
  201. $filesize = round($filesize,2);
  202. $filesize = $filesize."mb";
  203. }
  204. if ($filesize!='0'){
  205. echo "<option value='$row'>".$lang['upload_remove']." $original_filename ($filesize)</option>";
  206. }
  207. else{
  208. echo "<option value='$row'>".$lang['upload_remove']." $original_filename</option>";
  209. }
  210. }
  211. echo "</select>";
  212. ?>
  213. </div>
  214. <div style="width: 50%; float: left; text-align: right;">
  215. <script type="text/javascript">
  216. function type_select() {
  217. val = document.form1.fileadd.options[document.form1.fileadd.selectedIndex].value;
  218. textbox = parent.document.postcontent.content;
  219. //IE support
  220. if (document.selection) {
  221. textbox.focus();
  222. sel = document.selection.createRange();
  223. sel.text = val;
  224. textbox.focus();
  225. }
  226. //MOZILLA/NETSCAPE support
  227. else if (textbox.selectionStart || textbox.selectionStart == '0') {
  228. var startPos = textbox.selectionStart;
  229. var endPos = textbox.selectionEnd;
  230. var scrollTop = textbox.scrollTop;
  231. textbox.value = textbox.value.substring(0, startPos)
  232. + val
  233. + textbox.value.substring(endPos, textbox.value.length);
  234. textbox.focus();
  235. textbox.selectionStart = startPos + val.length;
  236. textbox.selectionEnd = startPos + val.length;
  237. textbox.scrollTop = scrollTop;
  238. } else {
  239. textbox.value += val;
  240. textbox.focus();
  241. }
  242. }
  243. </script>
  244. <select name="fileadd" onchange="type_select()">
  245. <?php
  246. echo "<option value=''>".$lang['upload_add']."</option>";
  247. $query211 = "select ORIGINAL_FILENAME, FILESIZE, ROW from {$db_prefix}attachments WHERE hash='$hash' ORDER BY ORIGINAL_FILENAME desc" ;
  248. $result211 = mysql_query($query211) or die("Query failed2") ;
  249. while ($results211 = mysql_fetch_array($result211)){
  250. $original_filename = $results211['ORIGINAL_FILENAME'];
  251. $row = $results211['ROW'];
  252. echo "<option value='[attachment=$row]'>".$lang['upload_insert']." $original_filename [$row]</option>";
  253. }
  254. ?>
  255. </select>
  256. </div>
  257. <?php
  258. }
  259. echo "</form>";
  260. if($_GET['attachtype']=='avatar'){
  261. echo "<table style='width: 100%;'>";
  262. echo "<tr>";
  263. echo "<td style='font-size: 12px; vertical-align: bottom; width: 80%;'>";
  264. echo "<form enctype='multipart/form-data' method='post' action='uploader.php'>";
  265. echo "<input type='hidden' name='MAX_FILE_SIZE' value='100000000000' />";
  266. echo "<input type='hidden' name='topicid' value='$topicid' />";
  267. echo "<input type='hidden' name='member' value='$get_id' />";
  268. echo "<input type='hidden' name='attachtype' value='$attachtype' />";
  269. echo "<input type='hidden' name='hash' value='$hash' />";
  270. echo "<div class='center'>";
  271. echo "<input type='file' style='width: auto;' name='uploadedfile'>";
  272. echo "&nbsp;<input type='submit' class='submit-button img-upload' onClick=\"form_submit();\" value='$lang[button_upload]' /></div>";
  273. echo "</td>";
  274. echo "<td style='width: 20%;'> </td></tr>";
  275. echo "</form>";
  276. echo "</table>";
  277. }else{
  278. echo "<div class='spacer'>&nbsp;</div>";
  279. echo "<table style='width: 100%; height: 22px;' cellspacing='0' cellpadding='0'>";
  280. echo "<tr>";
  281. echo "<td style='font-size: 12px;'>Attach:</td>";
  282. echo "<td style='font-size: 12px;'>";
  283. echo "<form enctype='multipart/form-data' method='post' action='uploader.php'>";
  284. echo "<input type='hidden' name='MAX_FILE_SIZE' value='100000000000' />";
  285. echo "<input type='hidden' name='topicid' value='$topicid' />";
  286. echo "<input type='hidden' name='member' value='$get_id' />";
  287. echo "<input type='hidden' name='attachtype' value='$attachtype' />";
  288. echo "<input type='hidden' name='hash' value='$hash' />";
  289. echo "<input type='file' style='width: auto;' name='uploadedfile'>";
  290. echo "&nbsp;<input type='submit' class='submit-button img-upload' onClick=\"form_submit();\" value='$lang[button_upload]' /></div>";
  291. echo "</td></tr>";
  292. echo "</form>";
  293. echo "</table>";
  294. }
  295. }
  296. echo "</div>";
  297. ?>
  298. <div id="loadbg">
  299. <div id="loadbox"><div class="upload-box"><br /><br /><?php echo $lang['upload_box']; ?></div></div>
  300. <?php
  301. echo "</body>";
  302. echo "</html>";
  303. ?>