MyBB Community Forums

Full Version: let's give allow_url_fopen to mybb anyway
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
... if you have curl library...

the problem
when you try to use remote avatar if you don't have set to true the allow_url_fopen in your (your host) php.ini you could not use the avatar because server politic don't grant to u the ability to have access to remote file (file placed in other server).

the solution
use the curl library

the requirements
- you must have the curl library, of course

- create and give chmod to the directory in your forum: /uploads/tmpavatar

- add the code of the new my_getimagesize function in inc/functions.php

- change every getimagesize function call in my_getimagesize [there is in three file: usercp.php, functions_upload.php, functions_image]


the code
PHP Code:
function my_getimagesize($url)
{
  if (
eregi('^(http|ftp)://'substr($url010))) {
    if (!
ini_get('allow_url_fopen')) {
      
$ch curl_init($url);
      
$n 'uploads/tmpavatar/tmp'.str_replace(array(" ",'.'),array('',''),microtime());
      
$fn tempnam("",$n); 
      
$fp fopen($n"w"); 
      
curl_setopt($chCURLOPT_FILE$fp);
      
curl_setopt($chCURLOPT_HEADER0);
      
curl_exec($ch);
      
curl_close($ch);
      
$ret = @getimagesize($n);
      
unlink($n);
      return 
$ret;      
    }
  }        

Reference URL's