<?php
function portalimg_upload($input_portalimg, $img_error == FALSE) {
require_once MYBB_ROOT."inc/functions_upload.php";
$input_portalimg = preg_replace("#script:#i", "", $input_portalimg);
$ext = get_extension($input_portalimg);
if(preg_match("#^(gif|jpg|jpeg|jpe|bmp|png)$#i", $ext)) {
$path = $mybb->settings['uploadspath']."/posts";
$filename = "img_post_".md5(random_str(8)).".".$ext;
$file = upload_file(fetch_remote_file(basename($input_portalimg)), $path, $filename);
if($file['error']) {
@unlink($path."/".$filename);
$img_error == TRUE;
}
if(!file_exists($path."/".$filename)) {
@unlink($path."/".$filename);
$img_error == TRUE;
}
}
else {
$img_error == TRUE;
}
$portal_array = array(
"error" => $img_error,
"src" => $filename,
);
return $portal_array;
}
<?php
define("FILE_PUT_CONTENTS_ATOMIC_TEMP", $mybb->settings['uploadspath']."/posts");
define("FILE_PUT_CONTENTS_ATOMIC_MODE", 0777);
function portalimg_upload($input_img, $img_error = FALSE) {
$input_img = preg_replace("#script:#i", "", $input_img);
$ext = get_extension($input_img);
$input_img = file_get_contents($input_img);
if(preg_match("#^(gif|jpg|jpeg|jpe|bmp|png)$#i", $ext)) {
$filename = random_str(10)."_image.".$ext;
$temp = md5(time().rand());
$f = @fopen($temp, 'wb');
if (!($f = @fopen($temp, 'wb'))) {
$img_error = TRUE;
}
fwrite($f, $input_img);
fclose($f);
if (!@rename($temp, $filename)) {
@unlink($filename);
@rename($temp, $filename);
@chmod($filename, FILE_PUT_CONTENTS_ATOMIC_MODE);
if(copy(MYBB_ROOT.$filename, FILE_PUT_CONTENTS_ATOMIC_TEMP."/".$filename)) {
@unlink(MYBB_ROOT.$filename);
}
}
}
else {
$img_error == TRUE;
}
$portal_array = array(
"error" => $img_error,
"src" => $filename,
);
return $portal_array;
}