Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- $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);
- $title = $_POST["title"];
- if (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) {
- $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);
- // print "jfdijfksdjfkdf";
- }
- }
- function make_thumb($img_name,$filename,$new_w,$new_h)
- {
- //get image extension.
- $ext=getExtension($img_name);
- //creates the new image using the appropriate function from gd library
- if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext))
- $src_img=imagecreatefromjpeg($img_name);
- if(!strcmp("png",$ext))
- $src_img=imagecreatefrompng($img_name);
- //gets the dimmensions of the image
- $old_x=imageSX($src_img);
- $old_y=imageSY($src_img);
- $dst_img=ImageCreateTrueColor($new_w,$new_h);
- imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,$old_x,$old_y);
- if(!strcmp("png",$ext))
- imagepng($dst_img,$filename);
- else
- imagejpeg($dst_img,$filename);
- imagedestroy($dst_img);
- imagedestroy($src_img);
- }
- function getExtension($str) {
- $i = strrpos($str,".");
- if (!$i) { return ""; }
- $l = strlen($str) - $i;
- $ext = substr($str,$i+1,$l);
- return $ext;
- }
- $errors=0;
- if(isset($_POST['Submit']))
- {
- $image=$_FILES['image']['name'];
- // if it is not empty
- if ($image)
- {
- // get the original name of the file from the clients machine
- $filename = stripslashes($_FILES['image']['name']);
- // get the extension of the file in a lower case format
- $extension = getExtension($filename);
- $extension = strtolower($extension);
- // if it is not a known extension, we will suppose it is an error, print an error message and will not upload the file, otherwise we continue
- if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png"))
- {
- //echo '<h1>Unknown extension!</h1>';
- $errors=1;
- }
- else
- {
- // get the size of the image in bytes
- // $_FILES[\'image\'][\'tmp_name\'] is the temporary filename of the file in which the uploaded file was stored on the server
- $size=getimagesize($_FILES['image']['tmp_name']);
- $sizekb=filesize($_FILES['image']['tmp_name']);
- }} }
- // End of thumbnail function
- if (($_FILES["image"]["type"] == "image/gif")
- || ($_FILES["image"]["type"] == "image/jpeg")
- || ($_FILES["image"]["type"] == "image/pjpeg")
- || ($_FILES["image"]["type"] == "image/png")) {
- if ($_FILES["image"]["error"] > 0) {
- //echo "Error: " . $_FILES["image"]["error"] . "<br />";
- } else {
- //echo "Title: " . $title . "<br />";
- //echo "Upload: " . $_FILES["image"]["name"] . "<br />";
- //echo "Type: " . $_FILES["image"]["type"] . "<br />";
- //echo "Size: " . ($_FILES["image"]["size"] / 1024) . " Kb<br />";
- if (file_exists("uploads/" . $_FILES["image"]["name"])) {
- //echo $_FILES["image"]["name"] . "already exists. ";
- //md5_file($_FILES["image"]["tmp_name"])
- continue;
- } else {
- $endfilename = stripslashes($_FILES['image']['name']);
- $extension = getExtension($filename);
- $extension = strtolower($extension);
- $endfilename = time() . "." . $extension;
- move_uploaded_file ($_FILES["image"]["tmp_name"],
- "uploads/" . $endfilename);
- $filename = $endfilename;
- $srcth = $endfilename;
- move_uploaded_file ($_FILES["image"]["tmp_name"],
- "uploads/" . $_FILES["image"]["name"]);
- //$filename = "uploads/" . $_FILES["image"]["name"];
- //$srcth = "uploads/thumbs/" . $_FILES["image"]["name"];
- //echo "Stored: " . $filename;
- //Make thumbnails and insert information into database
- $one = "uploads/$filename";
- $two = "uploads/thumbs/$filename";
- make_thumb($one,$two,200,125);
- $title = mysql_real_escape_string($title);
- $filename = mysql_real_escape_string($filename);
- $tags = mysql_real_escape_string($tags);
- if ($db_found) {
- $time = date("Y-n-j ~ H:i A");
- $SQL = "INSERT INTO tb_images (img_id, img_name, filename, user) VALUES (NULL, '$title', '$filename', '$usersend')";
- $result = mysql_query($SQL);
- mysql_close($db_handle);
- }
- else {
- //print "Database Not Found ";
- mysql_close($db_handle);
- //header('Location: index.php');
- }
- }
- }
- } else {
- //echo "Something went wrong...";
- $prev = $_SERVER['HTTP_REFERER'];
- header("Location: $prev");
- }
- $prev = $_SERVER['HTTP_REFERER'];
- header("Location: $prev");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment