can help me to intergarate this in php

Discussion in 'PHP' started by ironmankho, Oct 16, 2008.

Thread Status:
Not open for further replies.
  1. #1
    a friend of mine . coded a php remote uploade script for me .

    it is very simple . upload your image .than it will remote upload to tinypic.com ...

    it is amazing . try demo

    http://image.test.wdus.org/

    <?php
    function checklink($filename, $filesize, $filetype) {
    $filename2 = explode(".", $filename);
    foreach ($filename2 as $key => $value) {
    $filename2 = $value;
     }
    if ($filename2 == $filename) {
    $error = "File Is Without Extention";
     }
    $filname3 = str_replace($filename2, md5("runcode"), "jpg gif png jpeg bmp");
    if ($error == "") {
    if (preg_match("/".md5("runcode")."/i", $filname3)) {
      }else{
     $error = ".$filename2 Is Inavlid Type ";
      }
     }
    if ($error == "") {
    if (substr($filetype, 0, 5) == "image") {
      }else{
     $error = "Uploaded File Is Not Image";
      }
     }
    if ($error == "") {
    $size = "2000";
    $size = $size*1000;
    if ($size > $filesize) {
      }else{
     $error = "Your File Size Is Large Than 2 Mb";
      }
     }
    if ($error != "") {
    return $error;
     }else{
    return "yes";
     }
    }
    function im2link($data) {
        $ed = explode('>', $data);
        foreach ($ed as $key => $value) {
            if (substr(trim($value), 0, 3) == '<in') {
                unset($el); $e1 = explode('name="pic"', $value);
                unset($z1);
                if (isset($e1[1])) { $z1 = explode("\"", $e1[1]); $picid = $z1[1]; }
                
                unset($el); $e1 = explode('name="ival"', $value);
                if (isset($e1[1])) { $z1 = explode("\"", $e1[1]); $picserver = $z1[1]; }
                
            }
    
        }
        if (isset($picid) && isset($picserver)) { return "http://i".$picserver.".tinypic.com/".$picid; }
    }
    if (isset($_POST['MAX_FILE_SIZE'])){
        $err = checklink(strtolower($_FILES['file']['name']), $_FILES['file']['size'], $_FILES['file']['type']);
    if ($err == "yes") {
          $file=$_FILES['file']['tmp_name'];
          $eer = explode('.', $_FILES['file']['name']);
          $ch = curl_init('http://s4.tinypic.com/upload.php');  
          curl_setopt($ch, CURLOPT_POSTFIELDS, array('domain_lang'=>"en",'action'=>'upload','MAX_FILE_SIZE'=>'200000000','the_file'=>"@$file",'description'=>'','file_type'=>'image','dimension'=>'1600'));
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          $postResult = curl_exec($ch);
          curl_close($ch);
          if (im2link($postResult) != '') { die('<input name="piclink" onclick="this.select()" value="[IMG]'.im2link($postResult).'.'.$eer[count($eer)-1].'[/IMG]" size="41"><br><a href="'.$_SERVER['SCRIPT_NAME'].'">Upload More</a>'); }else{ die('<a href="'.$_SERVER['SCRIPT_NAME'].'">Try Again</a>'); }
     }else{
     die($err.'<br><a href="'.$_SERVER['SCRIPT_NAME'].'">Try Again</a>');
     }
    }
    ?>
    <form enctype="multipart/form-data" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post" >
          <input type="hidden" name="MAX_FILE_SIZE" value="200000000" />
          Choose an image to upload:<br>
          <input name="file" type="file" size="29" /><br />
          <input type="submit" value="Upload File" />
    </form>
    PHP:
    now my question is can any body integrate this watermark code in this script .
    <?php  
    
    header('content-type: image/jpeg');  
    
    $watermark = imagecreatefrompng('watermark.png');  
    $watermark_width = imagesx($watermark);  
    $watermark_height = imagesy($watermark);  
    $image = imagecreatetruecolor($watermark_width, $watermark_height);  
    $image = imagecreatefromjpeg($_GET['src']);  
    $size = getimagesize($_GET['src']);  
    $dest_x = $size[0] - $watermark_width - 5;  
    $dest_y = $size[1] - $watermark_height - 5;  
    imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);  
    imagejpeg($image);  
    imagedestroy($image);  
    imagedestroy($watermark);  
    
    ?>
    PHP:
    actually i read this from site point complete tutorial at this site



    http://www.sitepoint.com/article/watermark-images-php/


    for some reason i don't want to bother my friend again ......

    please help .because i am newbie ..... no idea how i can done ?
     
    ironmankho, Oct 16, 2008 IP
Thread Status:
Not open for further replies.