Advertisement
Guest User

teste

a guest
Oct 31st, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.73 KB | None | 0 0
  1. <?php
  2.  
  3. //#####################################################################################
  4.  
  5. //This script processes the uploaded images, puts a watermark on it, insert records
  6. // into the database and also shows code for each image.
  7.  
  8. //#####################################################################################
  9.  
  10.  
  11. session_start();
  12. $session = false;
  13.  
  14. include("db-info.php");
  15. $link = mysql_connect($server, $user, $pass);
  16. if(!mysql_select_db($database)) die(mysql_error());
  17.  
  18. include("loadsettings.inc.php");
  19.  
  20. $type = "public";
  21.  
  22. if (isset($_SESSION["imagehost-user"]))
  23. {
  24. $session = true;
  25. $username = $_SESSION["imagehost-user"];
  26. $password = $_SESSION["imagehost-pass"];
  27.  
  28.  
  29. $q = "SELECT id FROM `members` WHERE (username = '$username') and (password = '$password')";
  30. if(!($result_set = mysql_query($q))) die(mysql_error());
  31. $number = mysql_num_rows($result_set);
  32.  
  33. if (!$number) {
  34. session_destroy();
  35. $session = false;
  36. }else {
  37. $row = mysql_fetch_row($result_set);
  38. $loggedId = $row[0];
  39.  
  40. if (isset($_POST["tags1"])) {
  41.  
  42. $opt = $_POST['opt'];
  43. if ($opt == "gallery") {
  44. $galleryid = $_POST["galleryid"];
  45. $result = mysql_query("SELECT type FROM `galleries` WHERE id = '$galleryid'");
  46. $n = mysql_num_rows($result);
  47. if (!$n) die();
  48. $row = mysql_fetch_array($result);
  49. $type = $row['type'];
  50. }
  51. else {
  52. if (isset($_POST["private"]))
  53. $type = "private";
  54. else
  55. $type = "public";
  56. }
  57.  
  58. }
  59. }
  60.  
  61.  
  62. }
  63. else
  64. $session = false;
  65.  
  66. //*************************************************************************************************
  67.  
  68. ?>
  69.  
  70.  
  71. <html>
  72.  
  73. <head>
  74.  
  75. <title><? echo $webtitle; ?> - Free Image Hosting</title>
  76. <link rel="stylesheet" href="style.css" type="text/css" />
  77. </head>
  78.  
  79.  
  80. <body link=#336699 vlink=#336699 alink=#336699>
  81. <?php include("header.php"); ?>
  82.  
  83. <center>
  84. <div class="content-container">
  85.  
  86.  
  87. <!-- ############################################################################################### -->
  88.  
  89. <?php
  90.  
  91.  
  92. function findExtension ($filename)
  93. {
  94. $filename = strtolower($filename) ;
  95. $exts = split("[/\\.]", $filename) ;
  96. $n = count($exts)-1;
  97. $exts = $exts[$n];
  98. return $exts;
  99. }
  100.  
  101.  
  102. function imagecreatefromunknown($path) {
  103.  
  104. $ext = findExtension($path);
  105.  
  106. switch ($ext) {
  107. case "jpg":
  108. $img = imagecreatefromjpeg($path);
  109. break;
  110. case "gif":
  111. $img = imagecreatefromgif($path);
  112. break;
  113. case "png":
  114. $img = imagecreatefrompng($path);
  115. break;
  116. }
  117.  
  118. return $img;
  119. }
  120.  
  121.  
  122.  
  123. $max = 5;
  124. $total = 0;
  125.  
  126.  
  127. if (isset($_POST["tags1"])) {
  128.  
  129. $date = date("d-m-y");
  130. $lastaccess = date("y-m-d");
  131. $ip= $_SERVER['REMOTE_ADDR'];
  132.  
  133. //CHECK IF THE IP OF THE PERSON IS BLOCKED OR NOT
  134. $result = mysql_query("SELECT id FROM `blockedip` WHERE ip = '$ip'");
  135. $number = mysql_num_rows($result);
  136. if ($number) die("Sorry ! Your ip is blocked from uploading any image. <br><br><a href='index.php'>Go back to homepage</a>");
  137.  
  138.  
  139. for ($i=1; $i < ($max+1); $i++)
  140. {
  141. if (trim($_FILES["image" . $i]["name"]) != "") {
  142.  
  143. $total = $total + 1;
  144. if ( (trim($_POST["tags" . $i]) != "") ) {
  145.  
  146. $tags = htmlspecialchars(trim($_POST["tags" . $i]));
  147.  
  148. $name = "image" . $i;
  149.  
  150. //CHECK IF VALID IMAGE TYPE
  151. if (( ($_FILES[$name]["type"] == "image/gif")
  152. || ($_FILES[$name]["type"] == "image/jpeg")
  153. || ($_FILES[$name]["type"] == "image/pjpeg")
  154. || ($_FILES[$name]["type"] == "image/x-png")
  155. || ($_FILES[$name]["type"] == "image/bmp")
  156. || ($_FILES[$name]["type"] == "image/png")))
  157. {
  158.  
  159. $size = intval(($_FILES[$name]["size"] / 1024) / 1024);
  160.  
  161. if ($session == true)
  162. $limit = $maxsizemember;
  163. else
  164. $limit = $maxsizeguest;
  165.  
  166. if ($size > $limit)
  167. die ("Sorry ! The size of the image exceeds the $limit Mb limit.");
  168.  
  169.  
  170. if ($_FILES[$name]["error"] > 0) {
  171. die("Error: " . $_FILES[$name]["error"]);
  172. }
  173. else {
  174. $n = $_FILES[$name]["name"];
  175. $rndName = md5($n . date("d-m-y") . time()) . "." . findExtension($n);
  176. $uploadPath = "pictures/" . $rndName;
  177. $tempPath = $_FILES[$name]["tmp_name"];
  178. move_uploaded_file($tempPath, $uploadPath);
  179. }
  180.  
  181. }
  182. else
  183. die("Sorry ! \"{$_FILES[$name]["name"]}\" is an invalid image.");
  184.  
  185.  
  186. $imagePath = $uploadPath;
  187.  
  188. //********************************************************************************************************
  189.  
  190. $img = imagecreatefromunknown($imagePath);
  191.  
  192. $mainWidth = imagesx($img);
  193. $mainHeight = imagesy($img);
  194.  
  195. if (($mainWidth > 150) && ($mainWidth < 2000) && ($mainHeight < 1600))
  196. {
  197.  
  198. $a = ($mainWidth >= $mainHeight) ? $mainWidth : $mainHeight;
  199.  
  200. $div = $a / 150;
  201. $thumbWidth = intval($mainWidth / $div);
  202. $thumbHeight = intval($mainHeight / $div);
  203.  
  204.  
  205. $myThumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
  206. imagecopyresampled($myThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $mainWidth, $mainHeight);
  207. $thumbPath = "thumbnails/" . basename($imagePath);
  208. imagejpeg($myThumb, $thumbPath);
  209.  
  210.  
  211.  
  212. //********************************************************************************************************
  213.  
  214. if (($type == "public") && ($watermark == "true")) {
  215. $imgMark = imagecreatefromgif("watermark.gif");
  216.  
  217. $dX = $mainWidth - imagesx($imgMark);
  218. $dY = $mainHeight - imagesy($imgMark);
  219. imagecopymerge($img, $imgMark, $dX, $dY, 0, 0, imagesx($imgMark), imagesy($imgMark), 40);
  220.  
  221. $ext = findExtension($imagePath);
  222.  
  223. switch ($ext) {
  224. case "jpg":
  225. imagejpeg($img, $imagePath); break;
  226. case "png":
  227. imagepng($img, $imagePath); break;
  228. }
  229. }
  230.  
  231. //******************************************************************************************************
  232.  
  233. $details = intval(filesize($imagePath) / 1024) . " kb (" . $mainWidth . " x " . $mainHeight . ")" ;
  234. $id = md5($thumbPath . date("d-m-y") . time());
  235.  
  236. //#########################################################################################################
  237.  
  238. if ($session == false)
  239. $q = "INSERT INTO `images`(id, image, thumb, tags, details, date, access, type, ip)
  240. VALUES('$id', '$imagePath', '$thumbPath', '$tags', '$details', '$date', '$lastaccess', 'public', '$ip')";
  241. else
  242. {
  243. if ($opt == "gallery")
  244. $q = "INSERT INTO `images`(id, galleryid, image, thumb, tags, details, date, access, type, ip)
  245. VALUES('$id', '$galleryid', '$imagePath', '$thumbPath', '$tags', '$details', '$date', '$lastaccess', 'gallery', '$ip')";
  246. else
  247. $q = "INSERT INTO `images`(id, userid, image, thumb, tags, details, date, access, type, ip)
  248. VALUES('$id', '$loggedId', '$imagePath', '$thumbPath', '$tags', '$details', '$date', '$lastaccess', 'member-{$type}', '$ip')";
  249. }
  250.  
  251. if(!($result_set = mysql_query($q))) die(mysql_error());
  252.  
  253. echo "<center><a href=\"show-image.php?id=$id\"><img src='thumb.php?id=$id'></a></center><br>";
  254. echo "Image \"{$_FILES["image" . $i]["name"]}\" uploaded successfully. <br><br>";
  255.  
  256.  
  257. echo "<LABEL id='title'>HTML:</LABEL><br><input type='text' size=92 onclick=\"this.select();\" value=\"<a href='{$website}/show-image.php?id=$id'> <img src='{$website}/{$thumbPath}' alt='Image Hosting' border='0'> </a>\">";
  258. echo "<br><br>";
  259.  
  260.  
  261. echo "<LABEL id='title'>BB Code:</LABEL><br><input type='text' size=92 onclick=\"this.select();\" value=\"[URL={$website}/show-image.php?id={$id}] [IMG]{$website}/{$thumbPath}[/IMG][/URL]\">";
  262. echo "<br><br>";
  263.  
  264.  
  265. echo "<LABEL id='title'>Direct Image Link (HTML):</LABEL><br><input type='text' size=92 onclick=\"this.select();\" value=\"<a href='{$website}'> <img src='{$website}/{$imagePath}'> </a>\">";
  266. echo "<br><br>";
  267.  
  268.  
  269. echo "<LABEL id='title'>Direct Image Link (BB Code):</LABEL><br><input type='text' size=92 onclick=\"this.select();\" value=\"[URL={$website}] [IMG]{$website}/{$imagePath}[/IMG][/URL]\">";
  270. echo "<br><br>";
  271.  
  272. echo "<LABEL id='title'>URL:</LABEL><br><input type='text' size=92 onclick=\"this.select();\" value=\"{$website}/show-image.php?id=$id\">";
  273.  
  274. echo "<br><br><hr color='#233c9b'><br>";
  275.  
  276.  
  277. }
  278. else
  279. echo "Sorry ! Image \"{$_FILES["image" . $i]["name"]}\" is either too small or too large.<br><hr color='#b1ddf6'>";
  280.  
  281. }
  282. else
  283. echo "You have not entered any tags for the image \"{$_FILES["image" . $i]["name"]}\" <br><hr color='#b1ddf6'>";
  284. }
  285. }
  286.  
  287. }
  288.  
  289. if ($total == 0)
  290. echo "Sorry ! You must upload atleast one image.";
  291.  
  292.  
  293. ?>
  294.  
  295. <!-- ############################################################################################### -->
  296.  
  297.  
  298. <?php include("footer.php"); ?>
  299.  
  300. </div>
  301. </center>
  302. </body>
  303. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement