Activity Stream
48,167 MEMBERS
62067 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 6 of 6
  1.     
    #1
    Respected Developer
    Website's:
    X4B.org

    Default Image Upload in php. Code snippet #2

    My second code snippet for the day.

    Requirements:
    - CURL
    - PHP5

    PHP Code: 
    <?
    /*
    Name: Image Class

    Splitice - thewarezscene.org
    */
    class image{
            var 
    $login = array('user'=>false,'pass'=>false);
            private 
    $image '';
            
            function 
    image($img){
                
    $this->image=$img;
            }
            
            function 
    upload_im4ge($image) {
            
    $postParams = array ('v2'=>'1','image' => '@' $image );
            if(
    $this->login['user']&&$this->login['pass']){
                  
    $postParams['login_user'] = $this->login['user'];
                  
    $postParams['login_pass'] = $this->login['pass'];
                  
    $postParams['login'] = true;
            }
            
    $ch curl_init ();
            
    curl_setopt $chCURLOPT_URL'http://im4ge.info/api.php' );
            
    curl_setopt $chCURLOPT_POSTtrue );
            
    curl_setopt $chCURLOPT_NOPROGRESSfalse );
            
    //curl_setopt($ch, CURLOPT_HEADER, true);
            
    curl_setopt $chCURLOPT_TIMEOUT);
            
    curl_setopt $chCURLOPT_VERBOSE);
            
    curl_setopt $chCURLOPT_POSTFIELDS$postParams );
            
    curl_setopt $chCURLOPT_RETURNTRANSFER);
            
    $postResult curl_exec $ch );
            if (! 
    $postResult){
                
    curl_close($ch);
                return 
    false;
            }
            if (
    curl_errno $ch )) {
                
    trigger_error 'Unable to upload file: ' curl_error $ch ) );
                
    curl_close($ch);
                return 
    false;
            }
            
    curl_close $ch );
            
    $dd =  unserialize($postResult);
            return 
    $dd;
        }
        
        function 
    set_login($user$pass){
            
    $this->login['user'] = $user;
            
    $this->login['pass'] = $pass;
        }

        function 
    upload_img($nocache false){
            
    $i $this->image;
            if(
    $nocache===false&&substr($i,0,7)=='http://'){
                
    $res mysql_query('SELECT * FROM image_cache WHERE url="'.mysql_real_escape_string($i).'"');
                
    $row mysql_fetch_assoc($res);
                return 
    unserialize($row['data']);
            }
            
    $size = array();
            if (! 
    strpos $i'?' )) {
                
    $p pathinfo $i );
                
    $t tempnam '/tmp''img_' ) . '.' $p ['extension'];
                
    $d file_get_contents trim $i ) );
                if (! 
    $d) {
                    return array(
    false,'image not available');
                }
                
    file_put_contents $t$d );
                
    $d $this->upload_im4ge $t );
                
    $size getimagesize($t);
                
    unlink($t);
                if(
    $d===false){
                    return array(
    false,'upload failed');
                }
                if(
    $d['error']){
                    return array(
    false,'upload failed: '.$d['errormsg']);
                }
                
    $t = array ('url' => $i'bbcode' => $d );
                
    $i $t;
            }else{
                return array(
    false'dont upload');
            }
            if(!
    file_get_contents($i['bbcode']['thumbnail'])){
                
    $i['bbcode']['thumbnail'] = $i['bbcode']['image'];
            }
            
    $ret = array('thumbnail'=>$i['bbcode']['thumbnail'],'image'=>$i['bbcode']['image'],'link'=>$i['bbcode']['url'],'width'=>$size[0],'height'=>$size[1]);
            if(
    $nocache===false&&substr($i,0,7)=='http://'){
                
    mysql_query('INSERT INTO images_cache VALUES("'.mysql_real_escape_string($this->image).'","'.mysql_real_escape_string(serialize($ret)).'")');
            }
            return 
    $ret;
        }
        
        function 
    __toString(){
            return 
    $this->image;
        }
    }
    ?>
    Usage should be fairly self explanitory
    PHP Code: 
    $img = new image('local or remote image');
    $img->upload_img(); 
    Ill add watermark support to the class soon as well. Just for KWWHunction
    SplitIce Reviewed by SplitIce on . Image Upload in php. Code snippet #2 My second code snippet for the day. Requirements: - CURL - PHP5 <? /* Name: Image Class Rating: 5

  2.   Sponsored Links

  3.     
    #2
    Member
    This code would be compatible with the chevereto image upload script right. (watermarking once you show it)

  4.     
    #3
    Respected Developer
    Website's:
    X4B.org
    ? it is ment to be used externally e.g I use it in a script that creates screenshots of movies.

  5.     
    #4
    Member
    Thanks...
    very useful for me..
    Coding Horror Fan
    I don't read PM's frequently .

  6.     
    #5
    Member
    Quote Originally Posted by SplitIce View Post
    ? it is ment to be used externally e.g I use it in a script that creates screenshots of movies.
    Oh, sorry.
    I have no idea how to read php?

  7.     
    #6
    Respected Developer
    Website's:
    X4B.org
    Well the script is relatively simple, hence why I posted it here for people to learn off.

    Made a small update by the way:
    PHP Code: 
    <?
    /*
    Name: Image Class

    Splitice - thewarezscene.org
    */

    class image{
            var 
    $login = array('user'=>false,'pass'=>false);
            private 
    $image '';
            
            function 
    image($img){
                
    $this->image=$img;
            }
            
            function 
    upload_im4ge($image) {
            
    $postParams = array ('v2'=>'1','image' => '@' $image );
            if(
    $this->login['user']&&$this->login['pass']){
                  
    $postParams['login_user'] = $this->login['user'];
                  
    $postParams['login_pass'] = $this->login['pass'];
                  
    $postParams['login'] = true;
            }
            
    $ch curl_init ();
            
    curl_setopt $chCURLOPT_URL'http://im4ge.info/api.php' );
            
    curl_setopt $chCURLOPT_POSTtrue );
            
    curl_setopt $chCURLOPT_NOPROGRESSfalse );
            
    //curl_setopt($ch, CURLOPT_HEADER, true);
            
    curl_setopt $chCURLOPT_TIMEOUT);
            
    curl_setopt $chCURLOPT_VERBOSE);
            
    curl_setopt $chCURLOPT_POSTFIELDS$postParams );
            
    curl_setopt $chCURLOPT_RETURNTRANSFER);
            
    $postResult curl_exec $ch );
            if (! 
    $postResult){
                
    curl_close($ch);
                return 
    false;
            }
            if (
    curl_errno $ch )) {
                
    trigger_error 'Unable to upload file: ' curl_error $ch ) );
                
    curl_close($ch);
                return 
    false;
            }
            
    curl_close $ch );
            
    $dd =  unserialize($postResult);
            return 
    $dd;
        }
        
        function 
    set_login($user$pass){
            
    $this->login['user'] = $user;
            
    $this->login['pass'] = $pass;
        }

        function 
    upload_img($nocache false){
            
    $i $this->image;
            if(
    $nocache===false&&substr($i,0,7)=='http://'){
                
    $res mysql_query('SELECT * FROM image_cache WHERE url="'.mysql_real_escape_string($i).'"');
                
    $row mysql_fetch_assoc($res);
                return 
    unserialize($row['data']);
            }
            
    $size = array();
            if (!
    file_exists($i)) {
                
    $p pathinfo $i );
                
    $t tempnam '/tmp''img_' ) . '.' $p ['extension'];
                
    $d file_get_contents trim $i ) );
                if (! 
    $d) {
                    return array(
    false,'image not available');
                }
                
    file_put_contents $t$d );
                
    $d $this->upload_im4ge $t );
                
    $size getimagesize($t);
                
    unlink($t);
                if(
    $d===false){
                    return array(
    false,'upload failed');
                }
                if(
    $d['error']){
                    return array(
    false,'upload failed: '.$d['errormsg']);
                }
                
    $t = array ('url' => $i'bbcode' => $d );
                
    $i $t;
            }else{
                
    $d $this->upload_im4ge $i );
                
    $size getimagesize($i);
                if(
    $d===false){
                    return array(
    false,'upload failed');
                }
                if(
    $d['error']){
                    return array(
    false,'upload failed: '.$d['errormsg']);
                }
                
    $t = array ('url' => $i'bbcode' => $d );
                
    $i $t;
            }
            if(!
    file_get_contents($i['bbcode']['thumbnail'])){
                
    $i['bbcode']['thumbnail'] = $i['bbcode']['image'];
            }
            
    $ret = array('thumbnail'=>$i['bbcode']['thumbnail'],'image'=>$i['bbcode']['image'],'link'=>$i['bbcode']['url'],'width'=>$size[0],'height'=>$size[1]);
            if(
    $nocache===false&&substr($i,0,7)=='http://'){
                
    mysql_query('INSERT INTO images_cache VALUES("'.mysql_real_escape_string($this->image).'","'.mysql_real_escape_string(serialize($ret)).'")');
            }
            return 
    $ret;
        }
        
        function 
    __toString(){
            return 
    $this->image;
        }
    }
    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to code image in css and se in wordpress post?
    By BattleDuty in forum Wordpress
    Replies: 4
    Last Post: 14th Mar 2012, 11:54 AM
  2. [Hiring] code for Right click Image uploader
    By cool.guy.prince in forum Completed Transactions
    Replies: 2
    Last Post: 26th Jun 2011, 05:44 AM
  3. i need filesonic php upload code
    By chems in forum Web Development Area
    Replies: 26
    Last Post: 20th Feb 2011, 07:28 PM
  4. Insert Image Code
    By warezboy in forum vBulletin
    Replies: 12
    Last Post: 9th Jun 2010, 06:16 PM
  5. Insert Image CODE
    By tom247 in forum Web Application/Script Support
    Replies: 3
    Last Post: 9th Jun 2010, 05:04 AM

Tags for this Thread

BE SOCIAL