WEB PHP Function issue v. cURL

Discussion in 'OT Technology' started by Mikey, Dec 31, 2008.

  1. Mikey

    Mikey This one, this form I hold now, so Wide eyed and h

    Joined:
    Oct 18, 2001
    Messages:
    23,118
    Likes Received:
    0
    Location:
    Baltimore
    So, my web host has allow_url_fopen disabled and suggested to use curl instead. How can I adapt the below code to use cURL instead?


    from 'memcp.php':

    Code:
    $max_size = explode('x', $SETTINGS['max_avatar_size']);
            if (ini_get('allow_url_fopen')) {
                if ($max_size[0] > 0 && $max_size[1] > 0) {
                    $size = @getimagesize($_POST['newavatar']);
                    if ($size === false) {
                        $avatar = '';
                    } else if (($size[0] > $max_size[0] && $max_size[0] > 0) || ($size[1] > $max_size[1] && $max_size[1] > 0) && !X_SADMIN) {
                        error($lang['avatar_too_big'] . $SETTINGS['max_avatar_size'] . 'px', false);
                    }
                }
            } else if ($newavatarcheck == "no") {
                $avatar = '';
            }
     
  2. nashstradamus

    nashstradamus New Member

    Joined:
    Nov 2, 2003
    Messages:
    899
    Likes Received:
    0
    Location:
    East Coast, USA
    Sorry I cant help... but, GO RAVENS!
     
  3. Mikey

    Mikey This one, this form I hold now, so Wide eyed and h

    Joined:
    Oct 18, 2001
    Messages:
    23,118
    Likes Received:
    0
    Location:
    Baltimore
    :bigthumb:
     
  4. intrktevo

    intrktevo New Member

    Joined:
    Oct 18, 2004
    Messages:
    5,781
    Likes Received:
    0
    Location:
    UCF
  5. Mikey

    Mikey This one, this form I hold now, so Wide eyed and h

    Joined:
    Oct 18, 2001
    Messages:
    23,118
    Likes Received:
    0
    Location:
    Baltimore
  6. intrktevo

    intrktevo New Member

    Joined:
    Oct 18, 2004
    Messages:
    5,781
    Likes Received:
    0
    Location:
    UCF
    IM me on aim if you still have problems getting it to work..sames s/n as here
     
  7. Mikey

    Mikey This one, this form I hold now, so Wide eyed and h

    Joined:
    Oct 18, 2001
    Messages:
    23,118
    Likes Received:
    0
    Location:
    Baltimore
    I need to go back to coding on a regular basis because I'm just not getting it :rofl: now it constantly returns the avatar as null...

    Code:
    $max_size = explode('x', $SETTINGS['max_avatar_size']);
            if (ini_get('allow_url_fopen')) {
    		} elseif( (ini_get('allow_url_fopen') == 1 && $error == 1) || ini_get('allow_url_fopen') == 0 ) 
            {
               // if there was an error encountered while using fopen() OR if allow_url_fopen is OFF, use cURl
               if ( function_exists('curl_init') ) 
               {
                  $ch = curl_init();
                  curl_setopt($ch, CURLOPT_URL, $_POST['newavatar']);
                  curl_setopt($ch, CURLOPT_HEADER, 0);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
               
                  $data = curl_exec($ch);
                  curl_close($ch);}
                if ($max_size[0] > 0 && $max_size[1] > 0) {
                    $size = @getimagesize($_POST['newavatar']);
                    if ($size === false) {
                        $avatar = '';
                    } else if (($size[0] > $max_size[0] && $max_size[0] > 0) || ($size[1] > $max_size[1] && $max_size[1] > 0) && !X_SADMIN) {
                        error($lang['avatar_too_big'] . $SETTINGS['max_avatar_size'] . 'px', false);
                    }
                }
            } else if ($newavatarcheck == "no") {
                $avatar = '';
            }
     
  8. Karnejj

    Karnejj “A true conservative is one who can't see any diff OT Supporter

    Joined:
    Jan 9, 2008
    Messages:
    35,585
    Likes Received:
    0
    Location:
    UPGRADED USA Shutdown Today:8 derps
    It looks like you potentially download the image and place it into "$data":
    $data = curl_exec($ch); ​


    But, then it doesn't look like you ever actually reference that "$data" variable. You end up trying to use the $_POST variable again.
    $size = @getimagesize($_POST['newavatar']);​
     
  9. intrktevo

    intrktevo New Member

    Joined:
    Oct 18, 2004
    Messages:
    5,781
    Likes Received:
    0
    Location:
    UCF
    Code:
      $max_size = explode('x', $SETTINGS['max_avatar_size']);
            if (ini_get('allow_url_fopen')) {
                if ($max_size[0] > 0 && $max_size[1] > 0) {
                    $size = @getimagesize($_POST['newavatar']);
                    if ($size === false) {
                        $avatar = '';
                    } else if (($size[0] > $max_size[0] && $max_size[0] > 0) || ($size[1] > $max_size[1] && $max_size[1] > 0) && !X_SADMIN) {
                        error($lang['avatar_too_big'] . $SETTINGS['max_avatar_size'] . 'px', false);
                    }
                }
            } else if ( function_exists('curl_init') ) {
              //if fopen failed, and curl functions enabled
              
             echo "curl enabled.";
    
              /*
              
              Curl functions here
              
              */      
                
                
            } else if ($newavatarcheck == "no") {
                $avatar = '';
            }
    
     
  10. Karnejj

    Karnejj “A true conservative is one who can't see any diff OT Supporter

    Joined:
    Jan 9, 2008
    Messages:
    35,585
    Likes Received:
    0
    Location:
    UPGRADED USA Shutdown Today:8 derps
    From the code, it looks like he receives the URL of some avatar in a $_POST variable, and then he wants to check it's size.

    Since he can't use url_fopen, I guess he wants to download it with cURL and check it that way.
     
    Last edited: Dec 31, 2008
  11. Karnejj

    Karnejj “A true conservative is one who can't see any diff OT Supporter

    Joined:
    Jan 9, 2008
    Messages:
    35,585
    Likes Received:
    0
    Location:
    UPGRADED USA Shutdown Today:8 derps
    If the threadstarter can save files on his server via PHP, then just create a new (temporary) file, and fill it with the contents of "$data" ... then perform getimagesize on that file.
     
  12. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,767
    Likes Received:
    6
    curl_exec
     

Share This Page