Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $user_name = "username";
- $password = "password";
- $database = "database";
- $server = "127.0.0.1";
- $db_handle= mysql_connect($server, $user_name, $password);
- $db_found = mysql_select_db($database, $db_handle);
- $amount_page = 9;
- $pages = "<div id=\"pages\">";
- $SQL = "SELECT COUNT(img_id) from tb_images";
- $result = mysql_query($SQL);
- $row = mysql_fetch_row($result);
- $total_records = $row[0];
- $total_pages = ceil($total_records / $amount_page);
- if (isset($_GET["page"])) { $currentpage = $_GET["page"]; } else { $currentpage = 1; };
- $currentpage = mysql_real_escape_string(htmlentities($currentpage));
- $pages .= "<span class=\"pages\">";
- if ($total_pages > 0 && $currentpage > 1) {
- $pages .= "<a href=\"?page=" . (intval($currentpage) - 1) . "\">Prev « </a>";
- }
- if ($total_pages > 1) {
- for ( $i= 1; $i <= $total_pages; $i++) {
- $pages .= "<a href=\"?page=$i\"> $i </a> ";
- if ($i != $total_pages) {
- $pages .= " - ";
- }
- }
- }
- if ($total_pages > 0 && $currentpage != $total_pages && $total_pages > 1) {
- $pages .= "<a href=\"?page=" . (intval($currentpage) + 1) . "\"> » Next </a>";
- }
- $pages .= "</span>\n</div>";
- if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page = 1; };
- $loging = "
- <div id=\"upload\">
- <form enctype=\"multipart/form-data\" action=\"updity.php\" method=\"POST\" name=\"form\" onsubmit='return validate ()'>
- Title: <br>
- <input type=\"text\" name=\"title\" id=\"title\" class=\"input\" value=\"\"/> <br>
- <input type=\"file\" name=\"image\"> <br>
- <input name=\"Submit\" type=\"submit\" value=\"Upload image\"> <br>
- <span id=\"explain\" class=\"explain\">File must be .jpg, .gif or .png</span>
- </form>
- </div>
- <div id='imgwrap'>
- ";
- $start_from = ($page-1) * $amount_page;
- $SQL = "SELECT * FROM tb_images ORDER BY filename DESC LIMIT $start_from, $amount_page";
- $result = mysql_query($SQL);
- //print "<div id='wallcontainer'>";
- while ($db_field = mysql_fetch_assoc($result)) {
- $title = $db_field['title'];
- $filename = $db_field['filename'];
- $size = getimagesize("uploads/$filename");
- $thumb = "uploads/thumbs/" . $filename;
- $id = $db_field['img_id'];
- $endurl = $_SERVER['REQUEST_URI'];
- if (($pos = strpos($endurl, '?')) !== false) {
- $endurl = substr($endurl, 0, $pos);
- }
- $url = "http" . ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$endurl;
- $loging .= "<div class='img'>\n";
- $loging .= "<img src='uploads/thumbs/$filename' onClick=\"SelectAll('$id');\"><br>\n";
- $loging .= "<input type='text' value='$url"."uploads/$filename' id='$id' class='inp' onClick=\"SelectAll('$id');\">\n";
- $loging .= "<input type=\"button\" value=\"Delete\" class='inputdelete' onClick=\"parent.location='?action=delete&id=$id';\" >\n";
- $loging .= "</div>\n";
- }
- $loging .= "</div>\n";
- function Logout($user_id) {
- $SQL = "UPDATE tb_users SET online=0 WHERE user_id=$user_id";
- $result = mysql_query($SQL);
- setcookie('username','',time()-3600);
- setcookie('password','',time()-3600);
- $prev = $_SERVER['HTTP_REFERER'];
- header("Location: $prev");
- }
- function delete($img_id) {
- $SQL = "SELECT * FROM tb_images WHERE img_id=$img_id";
- $result = mysql_query($SQL);
- while ($db_field = mysql_fetch_assoc($result)) {
- $filename = $db_field['filename'];
- }
- $SQL = "DELETE FROM tb_images WHERE img_id=$img_id";
- $result = mysql_query($SQL);
- unlink("uploads/".$filename);
- unlink("uploads/thumbs/".$filename);
- $prev = $_SERVER['HTTP_REFERER'];
- header("Location: $prev");
- }
- if (isset($_GET['action'])) {
- if ($_GET['action'] == 'delete') {
- $img_id = mysql_real_escape_string(htmlentities($_GET['id']));
- delete($img_id);
- }
- }
- if (isset($_GET['action'])) {
- if ($_GET['action'] == 'logout') {
- $usersend = mysql_real_escape_string(htmlentities($_COOKIE['username']));
- Logout($usersend);
- }
- } elseif (isset($_COOKIE['username']) && isset($_COOKIE['password'])) {
- $usersend = mysql_real_escape_string(htmlentities($_COOKIE['username']));
- $passsend = mysql_real_escape_string(htmlentities($_COOKIE['password']));
- $md5pass = $passsend;
- $SQL = "SELECT user_id FROM tb_users WHERE username='$usersend' and password='$md5pass'";
- $result=mysql_query($SQL);
- $count=mysql_num_rows($result);
- while ($db_field = mysql_fetch_assoc($result)) {
- $id = $db_field['user_id'];
- $stamp = $db_field['timestamp'];
- }
- if($count==1) {
- //correct
- $time = time();
- $SQL = "UPDATE tb_users SET timestamp=$time WHERE user_id=$id";
- $result=mysql_query($SQL);
- $SQL = "UPDATE tb_users SET online=1 WHERE user_id=$id";
- $result=mysql_query($SQL);
- setcookie('username', $usersend, time()+60*60*24*365);
- setcookie('password', $md5pass, time()+60*60*24*365);
- $content = $loging;
- } else {
- //incorrect log
- $content = "Incorrect login";
- }
- } elseif (isset($_POST['username'])) {
- $usersend = mysql_real_escape_string(htmlentities($_POST['username']));
- $passsend = mysql_real_escape_string(htmlentities($_POST['password']));
- $md5pass = md5($passsend);
- $SQL = "SELECT user_id FROM tb_users WHERE username='$usersend' and password='$md5pass'";
- $result=mysql_query($SQL);
- $count=mysql_num_rows($result);
- while ($db_field = mysql_fetch_assoc($result)) {
- $id = $db_field['user_id'];
- $stamp = $db_field['timestamp'];
- }
- if($count==1) {
- $time = time();
- $SQL = "UPDATE tb_users SET timestamp=$time WHERE user_id=$id";
- $result=mysql_query($SQL);
- $SQL = "UPDATE tb_users SET online=1 WHERE user_id=$id";
- $result=mysql_query($SQL);
- setcookie('username', $usersend, time()+60*60*24*365);
- setcookie('password', $md5pass, time()+60*60*24*365);
- $content = $loging;
- } else {
- $content = "Incorrect login";
- }
- } elseif ($online == 1) {
- $time = time();
- $SQL = "UPDATE tb_users SET timestamp=$time WHERE user_id=$id";
- mysql_query($SQL);
- } else {
- $content = "
- <div id=\"Login\"><h1>Sign In</h1>
- <form id=\"Form_User_SignIn\" method=\"post\" action=\"" . $_SERVER['REQUEST_URI'] . "\">
- <li>
- <label for=\"Form_Username\">Username</label>
- <input id=\"Form_Email\" name=\"username\" value=\"\" class=\"InputBox\" type=\"text\"> </li>
- <li>
- <label for=\"Form_Password\">Password</label>
- <input id=\"Form_Password\" name=\"password\" value=\"\" class=\"InputBox Password\" type=\"password\"><a href=\"/\" class=\"ForgotPassword\">?</a></li>
- <li class=\"Buttons\">
- <input id=\"Form_SignIn\" name=\"signin\" value=\"Sign In\" class=\"Button\" type=\"submit\">
- </li>
- </ul>
- </div>
- </form></div></div>
- ";
- }
- ?>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
- "http://www.w3.org/TR/html4/strict.dtd\">
- <html>
- <head>
- <title>Image Upload</title>
- <link rel='stylesheet' type='text/css' href='style.css'>
- <script>
- function SelectAll(id)
- {
- document.getElementById(id).focus();
- document.getElementById(id).select();
- }
- </script>
- </head>
- <body>
- <div id="wrapper">
- <div id="wrap">
- <div class="left">
- <ul class="ulmenu">
- <li><a href="/" title="Home">Home</a></li>
- <li><a href="#" title="News">General News</a></li>
- <li><a href="/imgboard" title="Imageboard">Imageboard</a></li>
- </ul>
- </div>
- <div class="corner">
- </div>
- </div>
- <div id="content">
- <div id="stuff">
- <? echo $content; ?>
- </div>
- <div class="clear"></div>
- </div>
- <div id="footer">
- <a href='?action=logout'> Logout </a>
- <? echo $pages; ?>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment