Posted by Kode Fri 23rd Feb 2007 18:29 - Syntax is PHP - 16 viewsRun this post in the PHP shell
Download | New Post | Modify | Hide line numbers
PHP parser reported no syntax errors in this post!
  1. function backstr($haystack, $needle) {
  2.        return substr($haystack, 0, strlen($haystack) - strlen(strstr($haystack,$needle)));
  3. }
  4.  
  5. // Return random image code
  6.  
  7. function image_createThumb($src,$dest,$maxWidth,$maxHeight,$quality=100) {
  8.    if (file_exists($src)  && isset($dest)) {
  9.        // path info
  10.        $destInfo  = pathInfo($dest);
  11.        
  12.        // image src size
  13.        $srcSize  = getImageSize($src);
  14.        
  15.        // image dest size $destSize = width, $destSize = height
  16.        $srcRatio  = $srcSize[0]/$srcSize[1]; // width/height ratio
  17.        $destRatio = $maxWidth/$maxHeight;
  18.        if ($destRatio > $srcRatio) {
  19.            $destSize[1] = $maxHeight;
  20.            $destSize[0] = $maxHeight*$srcRatio;
  21.        }
  22.        else {
  23.            $destSize[0] = $maxWidth;
  24.            $destSize[1] = $maxWidth/$srcRatio;
  25.        }
  26.        
  27.        // path rectification
  28.        if ($destInfo['extension'] == "gif") {
  29.            $dest = substr_replace($dest, 'jpg', -3);
  30.        }
  31.        
  32.        // true color image, with anti-aliasing
  33.        $destImage = imageCreateTrueColor($destSize[0],$destSize[1]);
  34.        imageAntiAlias($destImage,true);
  35.        
  36.        // src image
  37.        switch ($srcSize[2]) {
  38.            case 1: //GIF
  39.            $srcImage = imageCreateFromGif($src);
  40.            break;
  41.            
  42.            case 2: //JPEG
  43.            $srcImage = imageCreateFromJpeg($src);
  44.            break;
  45.            
  46.            case 3: //PNG
  47.            $srcImage = imageCreateFromPng($src);
  48.            break;
  49.            
  50.            default:
  51.            return false;
  52.            break;
  53.        }
  54.        
  55.        // resampling
  56.        imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0,$destSize[0],$destSize[1],$srcSize[0],$srcSize[1]);
  57.        
  58.        // generating image
  59.        switch ($srcSize[2]) {
  60.            case 1:
  61.            case 2:
  62.            imageJpeg($destImage,$dest,$quality);
  63.            break;
  64.            
  65.            case 3:
  66.            imagePng($destImage,$dest);
  67.            break;
  68.        }
  69.        return true;
  70.    }
  71.    else {
  72.        return false;
  73.    }
  74. }
  75. function _execute_image_thumb($src, $dst, $height, $width) {
  76.     image_createThumb($src, $dst,$height,$width);
  77. }
  78. function options_myimages() {
  79. $succ = "false";
  80.     $user_var = $_SESSION["nicename"];
  81.     $dirpref = "../members/";
  82.     $dirthumb = "/thumb";
  83.     $delpic = $_GET['delpic'];
  84.     $setpic = $_GET['setasmain'];
  85.     $picid = $_GET['picid'];
  86.     if(isset($delpic) AND isset($picid)) {
  87.         unlink($dirpref.$user_var."/".$picid);
  88.         unlink($dirpref.$user_var.$dirthumb."/".$picid);
  89.     }
  90.     if(isset($setpic) AND isset($picid)) {
  91.         image_createThumb($dirpref.$user_var."/".$picid, $dirpref.$user_var.$dirthumb."/NPHM_site_main.jpg","184","184");
  92.         echo "\"refresh\" content=\"0;url=?page=pictures\">";
  93.     }
  94.     $dir = $dirpref.$user_var;
  95.     if ($_GET['action'] == "update") {
  96.         if (!is_dir($dirpref.$user_var)) {
  97.             mkdir($dirpref.$user_var);
  98.             chmod($dirpref.$user_var, 0777);
  99.         }
  100.         if (!is_dir($dirpref.$user_var.$dirthumb)) {
  101.             mkdir($dirpref.$user_var.$dirthumb);
  102.             chmod($dirpref.$user_var.$dirthumb, 0777);
  103.         }
  104.           //$dir = "path/where/you/want/to/upload/files/"; //Change this to the correct dir
  105.         //MIME types to allow, Gif, jpeg, zip ::Edit this to your liking
  106.           $types = array("image/gif","image/pjpeg","image/png", "image/jpeg");
  107.         //Check to determine if the submit button has been pressed
  108.         if(isset($_POST['submit'])){
  109.             //Shorten Variables
  110.              $tmp_name = $_FILES['upload']['tmp_name'];
  111.              $new_name = $_FILES['upload']['name'];
  112.             //Check MIME Type
  113.             if (in_array($_FILES['upload']['type'], $types)){
  114.                  //Move file from tmp dir to new location
  115.  
  116.                 if (move_uploaded_file($tmp_name,$dir . "/" . $new_name) == "TRUE") {
  117.             //    echo 'something'; flush();
  118.                                
  119. }
  120.             //    echo 'something'; flush();
  121.                   echo " was uploaded sucessfully!";
  122.                 //echo $dirpref.$user_var."/".$new_name, $dirpref.$user_var.$dirthumb."/".$new_name;
  123.             image_createThumb($dirpref.$user_var."/".$new_name, $dirpref.$user_var.$dirthumb."/".$new_name,"120","120");
  124.  
  125.                
  126.                } else {
  127.                 //Print Error Message
  128.                    echo "File Was Not Uploaded!
    "
    ;
  129.                 //Debug
  130.                 $name = $_FILES['upload']['name'];
  131.                 $type = $_FILES['upload']['type'];
  132.                 $size = $_FILES['upload']['size'];
  133.                 $tmp = $_FILES['upload']['name'];
  134.                 echo "Name: $name
    Type: $type
    Size: $size
    Tmp: $tmp"
    ;
  135.  
  136.             }
  137.         } else {
  138.             echo 'Could Not Upload Files';
  139.  
  140.         }
  141.     }
  142.  
  143.  
  144.     echo "Here at NPHM we has an open policy to nakedness.
    "
    ;
  145.     echo "In fact we openly encourage users to upload pics with the channel name written on    their naked body
    "
    ;
  146.     echo "However, we do ask that they are tasteful, and ANY pictures of this type MUST have [nsfw] in the filename
    "
    ;   
  147.     echo "i.e. mytoplesspic[nsfw].jpg or [nsfw]toplesspic.jpg this ensures casual visitors dont stumble across them.
    "
    ;
  148.     echo "Any users not respecting this policy may be removed";     
  149.     echo "
    \"
    ?page=pictures&action=update\" method=\"post\" enctype=\"multipart/form-data\">
  150.        
    Upload Pictures \"
    file\" name=\"upload\" />

  151.         \"submit\" name=\"submit\" value=\"Upload Files\" />
  152.         ";
  153.  
  154.     echo "Main Pic
    "
    ;
  155.         $nphmfile = "../members/$user_var/thumb/NPHM_site_main.jpg";
  156.     if (file_exists($nphmfile)) {
  157.         $main_img = "\"$nphmfile\" alt=\"NPHM_site_main.jpg\" />
    If you have updated the main pic, click refresh in your browser.

    ";
  158.     } else {
  159.         $main_img = "No Pic set as Main

    "
    ;
  160.     }
  161.     echo $main_img;
  162.     $a = '0';
  163.     $filepath = "$dirpref$user_var$dirthumb";
  164.     $url_path = "$dirpref$user_var";
  165.     if (file_exists($filepath)) {
  166.         $dir = dir($filepath);
  167.         $userpic = "\"center\" border=\"0\" cellpadding=\"5\" cellspacing=\"5\" width=\"100%\">";
  168.         while($entry=$dir->read()) {
  169.             if($entry == "." || $entry == ".." || $entry == "NPHM_site_main.jpg") {
  170.                 continue;
  171.             }
  172.             //  $fp = @fopen("$filepath/$entry","r");
  173.             if ($a == '0') { $userpic .= "
  174. "; }
  175.             $userpic .= "
  176. ";
  177.  
  178.             $a = $a + 1;
  179.             if ($a == '3') {
  180.                 $a = 0;
  181.                 $userpic .= "
  182. ";
  183.             }
  184.         }
  185.         $userpic .= "
  186. \"top\" id='n'>
  187.                        
  188.                        
  189.                         \"$filepath/$entry\" alt=\"$entry\">
  190.                         \"?page=pictures&setasmain=true&picid=$entry\">Set as Main
  191. "
    ;
  192.     } else {
  193.         $userpic = "
    \"center\">No Pics
    "
    ;
  194.     }
  195.     echo $userpic;
  196.  
  197.     //echo $dirpref.$user_var."/".$new_name, $dirpref.$user_var.$dirthumb."/".$new_name;
  198.    
  199. }
  200. if ($_SESSION["nickname"]) {
  201. options_myimages();
  202. }
  203. ?>

PermaLink to this entry https://pastebin.co.uk/10850
Posted by Kode Fri 23rd Feb 2007 18:29 - Syntax is PHP - 16 viewsRun this post in the PHP shell
Download | New Post | Modify | Hide line numbers

 

Comments: 0