Advertisement
Guest User

submitviaurl

a guest
Aug 15th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.12 KB | None | 0 0
  1. <?php
  2. include_once("../library/config.inc.php");
  3.  
  4. session_start();
  5.  
  6. include_once("myconnect.php");
  7. if(isset($_POST['submit']) && $_POST['key'] == $_SESSION['key']) {
  8. include_once("inc/easyphpthumbnail.class.php");
  9. include_once("inc/watermark.php");
  10.  
  11.     $replace_values = array(" ", "'", "\"", "\\", "/", "?", "|", "@", "#", "~", "!", "£", "$", "%", "^", "&", "*", "(", ")", "[", "]", "{", "}", "+", "=", "-", ":", ";", ",");
  12.  
  13. $imageURL = $_POST['url'];
  14. $dir = "../pictures/";
  15.  
  16.                 $randvar =  mt_rand(1,100);
  17.                 settype($randvar,"string");
  18. $image = ImageCreateFromString(file_get_contents($imageURL));
  19.  
  20. $newimagename = $randvar.str_replace($replace_values, "_", basename($imageURL));
  21.  
  22. $fimagename = $dir.$randvar.str_replace($replace_values, "_", basename($imageURL));
  23.  
  24. if (is_resource($image) === true)
  25. {
  26.     imagejpeg($image, $dir.$newimagename, 300);
  27.  
  28. }
  29.  
  30. else
  31. {
  32.     echo "Please Try With Valid Url .";
  33.     die();
  34. }
  35.  
  36. $width = imagesx($image);
  37.  
  38. $height = imagesy($image);
  39. $newwidth = $width;
  40. $newheight = $height;
  41. if($newwidth > 500)
  42. {
  43. $newwidth = 500;
  44. $newheight = (($height * $newwidth) / $width);
  45. }
  46. else if($_POST['pmcat_id'] == 2)
  47. {
  48. $newwidth = 320;
  49. $newheight = (($height * $newwidth) / $width);
  50. }
  51.  
  52. $thumbs = imagecreatetruecolor($newwidth, $newheight);
  53.  
  54. imagecopyresized($thumbs, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  55.  
  56. imagejpeg($thumbs, $fimagename); //save image as jpg
  57.  
  58. imagedestroy($thumbs);
  59.  
  60. imagedestroy($image);
  61.  
  62. include("watermark.php");
  63.  
  64.  $thumb = new easyphpthumbnail;
  65.  $thumb -> Thumbheight = 200;
  66.  $thumb -> Thumbwidth = 200;
  67.  $thumb -> Cropimage = array(3,0,0,0,0,0);
  68.  $thumb -> Thumblocation = "../pictures/";
  69.  $thumb -> Thumbprefix = 'tb_';
  70.  $thumb -> Thumbsaveas = 'jpg';
  71.  $thumb -> Thumbfilename = $fimagename;
  72.  $thumb -> Createthumb($fimagename,'file');
  73.  
  74.                 $pmgadget_title=str_replace("$","\$",addslashes($_REQUEST["subject"]));
  75.  
  76.         $pmcat_id=$_POST["pmcat_id"];
  77.         $tags = implode(',', $pmcat_id);
  78.  
  79.     $pmpic_path = $newimagename;
  80.         date_default_timezone_set("Asia/Karachi");
  81.  
  82.         $pmsubmit_date = date("YmdHis", time());
  83.  
  84.             $pmapproved="yes";
  85.                 $pmuser_id="1";
  86.                 $pmuser_name="Admin";
  87.             mysql_query("insert into pmgadget_gadget(pmcat_id, pmpic_path, pmuser_id, pmuser_name, pmgadget_title, pmsubmit_date, pmapproved) VALUES('$tags', '$pmpic_path', $pmuser_id, '$pmuser_name', '$pmgadget_title', $pmsubmit_date, '$pmapproved') ");
  88.         $lastid = mysql_insert_id();
  89.  
  90. $ext = pathinfo($newimagename, PATHINFO_EXTENSION); //$ext will be gif
  91.  
  92. $newname=$lastid.'.'.$ext;
  93.  
  94. echo 'before '.$newimagename.'<br />';
  95.  
  96. $oldt = $_SERVER['DOCUMENT_ROOT'].'/'.$thumbs_dir.'/tb_'.$newimagename;
  97. $newt = $_SERVER['DOCUMENT_ROOT'].'/'.$thumbs_dir.'/tb_'.$lastid.'.'.$ext;
  98. rename($oldt, $newt) or die("Unable to rename ".$oldt." to ".$newt.".");;
  99.  
  100. $old = $_SERVER['DOCUMENT_ROOT'].'/'.$pic_dir.'/'.$newimagename;
  101. $new = $_SERVER['DOCUMENT_ROOT'].'/'.$pic_dir.'/'.$lastid.'.'.$ext;
  102. rename($old, $new) or die("Unable to rename ".$old." to ".$new.".");;
  103.  
  104. echo 'after '.$lastid.'.'.$ext.'<br />';
  105.  
  106. $update = mysql_query("UPDATE $db_table SET $ppic_url='".$newname."' WHERE $approved='yes' AND $post_id=$lastid") or die("Error");
  107.  
  108.                 echo "<br /> Subject of Uploaded Content : ".
  109. $pmgadget_title." <br />";
  110. echo "In ".$tags."<br />";
  111.             echo "<img src='http://".$_SERVER["SERVER_NAME"] ."/pictures/tb_".$newimagename."' width='150' height='135'> <br /> Image Has Been Posted Successfully .";
  112. $tags = explode(',',$tags);
  113.             foreach($tags as $tag){
  114.  
  115.         mysql_query("update $category_table SET post_counts = post_counts+1 WHERE $category_id ='.$tag.'");
  116.  
  117. }
  118. }
  119.  
  120. $_SESSION['key'] = mt_rand(1, 1000);
  121. ?>
  122. <html>
  123. <head>
  124. <title>Submit Via Url</title>
  125.  
  126. <script src="<?php echo $site_path;?>library/jquery.js" type="text/javascript"></script>
  127. <script src="<?php echo $site_path;?>library/jquery.validate.js" type="text/javascript"></script>
  128. <script src="inc/main.js" type="text/javascript"></script>
  129.  
  130. <script type="text/javascript">
  131. $(document).ready(function() {
  132.     $("#form1").validate();
  133. });
  134. </script>
  135.  
  136. </head>
  137. <body>
  138. <?php
  139. echo'<b>Upload Picture Via URL</b>';
  140. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement