Vergleich inc/functions_upload.php - 1.8.3 - 1.8.11

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 204Zeile 204
	}

// Check we have a valid extension

	}

// Check we have a valid extension

	// This is attached to the attachment types allowed to be uploaded (set in the ACP)
$valid_extensions = array();
$extensions = $cache->read("attachtypes");

foreach($extensions as $ext => $type)
{
if(substr($type['mimetype'], 0, 5) == 'image')
{
$valid_extensions[$ext] = 1;
}
}

$ext = get_extension(my_strtolower($avatar['name']));

if(!isset($valid_extensions[$ext]))
{
$ret['error'] = $lang->error_avatartype;
return $ret;
}

    	$ext = get_extension(my_strtolower($avatar['name']));
if(!preg_match("#^(gif|jpg|jpeg|jpe|bmp|png)$#i", $ext))
{
$ret['error'] = $lang->error_avatartype;
return $ret;
}















if(defined('IN_ADMINCP'))
{


if(defined('IN_ADMINCP'))
{

Zeile 230Zeile 217
		$lang->load("messages", true);
}
else

		$lang->load("messages", true);
}
else

	{

	{

		$avatarpath = $mybb->settings['avataruploadpath'];
}

$filename = "avatar_".$uid.".".$ext;
$file = upload_file($avatar, $avatarpath, $filename);
if($file['error'])

		$avatarpath = $mybb->settings['avataruploadpath'];
}

$filename = "avatar_".$uid.".".$ext;
$file = upload_file($avatar, $avatarpath, $filename);
if($file['error'])

	{

	{

		delete_uploaded_file($avatarpath."/".$filename);
$ret['error'] = $lang->error_uploadfailed;
return $ret;

		delete_uploaded_file($avatarpath."/".$filename);
$ret['error'] = $lang->error_uploadfailed;
return $ret;

Zeile 272Zeile 259
				require_once MYBB_ROOT."inc/functions_image.php";
$thumbnail = generate_thumbnail($avatarpath."/".$filename, $avatarpath, $filename, $maxheight, $maxwidth);
if(!$thumbnail['filename'])

				require_once MYBB_ROOT."inc/functions_image.php";
$thumbnail = generate_thumbnail($avatarpath."/".$filename, $avatarpath, $filename, $maxheight, $maxwidth);
if(!$thumbnail['filename'])

				{

				{

					$ret['error'] = $lang->sprintf($lang->error_avatartoobig, $maxwidth, $maxheight);
$ret['error'] .= "<br /><br />".$lang->error_avatarresizefailed;
delete_uploaded_file($avatarpath."/".$filename);
return $ret;
}
else

					$ret['error'] = $lang->sprintf($lang->error_avatartoobig, $maxwidth, $maxheight);
$ret['error'] .= "<br /><br />".$lang->error_avatarresizefailed;
delete_uploaded_file($avatarpath."/".$filename);
return $ret;
}
else

				{



				{
// Copy scaled image to CDN
copy_file_to_cdn($avatarpath . '/' . $thumbnail['filename']);

					// Reset filesize
$avatar['size'] = filesize($avatarpath."/".$filename);
// Reset dimensions

					// Reset filesize
$avatar['size'] = filesize($avatarpath."/".$filename);
// Reset dimensions

Zeile 296Zeile 285
				delete_uploaded_file($avatarpath."/".$filename);
return $ret;
}

				delete_uploaded_file($avatarpath."/".$filename);
return $ret;
}

		}
}

// Next check the file size
if($avatar['size'] > ($mybb->settings['avatarsize']*1024) && $mybb->settings['avatarsize'] > 0)
{
delete_uploaded_file($avatarpath."/".$filename);
$ret['error'] = $lang->error_uploadsize;
return $ret;
}


		}
}










	// Check a list of known MIME types to establish what kind of avatar we're uploading

	// Check a list of known MIME types to establish what kind of avatar we're uploading

	switch(my_strtolower($avatar['type']))














	$attachtypes = (array)$cache->read('attachtypes');

$allowed_mime_types = array();
foreach($attachtypes as $attachtype)
{
if(defined('IN_ADMINCP') || is_member($attachtype['groups']) && $attachtype['avatarfile'])
{
$allowed_mime_types[$attachtype['mimetype']] = $attachtype['maxsize'];
}
}

$avatar['type'] = my_strtolower($avatar['type']);

switch($avatar['type'])

	{
case "image/gif":
$img_type = 1;

	{
case "image/gif":
$img_type = 1;

Zeile 323Zeile 317
		case "image/png":
case "image/x-png":
$img_type = 3;

		case "image/png":
case "image/x-png":
$img_type = 3;

 
			break;
case "image/bmp":
case "image/x-bmp":
case "image/x-windows-bmp":
$img_type = 6;

			break;
default:
$img_type = 0;

			break;
default:
$img_type = 0;

	}


	}


	// Check if the uploaded file type matches the correct image type (returned by getimagesize)

	// Check if the uploaded file type matches the correct image type (returned by getimagesize)

	if($img_dimensions[2] != $img_type || $img_type == 0)
{

	if(empty($allowed_mime_types[$avatar['type']]) || $img_dimensions[2] != $img_type || $img_type == 0)
{

		$ret['error'] = $lang->error_uploadfailed;
delete_uploaded_file($avatarpath."/".$filename);
return $ret;
}

		$ret['error'] = $lang->error_uploadfailed;
delete_uploaded_file($avatarpath."/".$filename);
return $ret;
}

 

// Next check the file size
if(($avatar['size'] > ($mybb->settings['avatarsize']*1024) && $mybb->settings['avatarsize'] > 0) || $avatar['size'] > $allowed_mime_types[$avatar['type']] && !($mybb->settings['avatarsize'] > 0))
{
delete_uploaded_file($avatarpath."/".$filename);
$ret['error'] = $lang->error_uploadsize;
return $ret;
}


	// Everything is okay so lets delete old avatars for this user
remove_avatars($uid, $filename);


	// Everything is okay so lets delete old avatars for this user
remove_avatars($uid, $filename);


Zeile 397Zeile 405
		return $ret;
}


		return $ret;
}


    $attachtypes = $cache->read('attachtypes');

    $attachtypes = (array)$cache->read('attachtypes');

    $attachment = $plugins->run_hooks("upload_attachment_start", $attachment);

    $attachment = $plugins->run_hooks("upload_attachment_start", $attachment);

 

$allowed_mime_types = array();
foreach($attachtypes as $ext => $attachtype)
{
if(!is_member($attachtype['groups']) || ($attachtype['forums'] != -1 && strpos(','.$attachtype['forums'].',', ','.$forum['fid'].',') === false))
{
unset($attachtypes[$ext]);
}
}


$ext = get_extension($attachment['name']);
// Check if we have a valid extension


$ext = get_extension($attachment['name']);
// Check if we have a valid extension

Zeile 483Zeile 500
			if(!@is_dir($mybb->settings['uploadspath']."/".$month_dir))
{
$month_dir = '';

			if(!@is_dir($mybb->settings['uploadspath']."/".$month_dir))
{
$month_dir = '';

 
			}
else
{
$index = @fopen($mybb->settings['uploadspath']."/".$month_dir."/index.html", 'w');
@fwrite($index, "<html>\n<head>\n<title></title>\n</head>\n<body>\n&nbsp;\n</body>\n</html>");
@fclose($index);

			}
}
}

			}
}
}

Zeile 611Zeile 634
	if($forumpermissions['modattachments'] == 1 && !is_moderator($forum['fid'], "canapproveunapproveattachs"))
{
$attacharray['visible'] = 0;

	if($forumpermissions['modattachments'] == 1 && !is_moderator($forum['fid'], "canapproveunapproveattachs"))
{
$attacharray['visible'] = 0;

	}
else

	}
else

	{
$attacharray['visible'] = 1;
}

	{
$attacharray['visible'] = 1;
}

Zeile 645Zeile 668
		$aid = $prevattach['aid'];
}
else

		$aid = $prevattach['aid'];
}
else

	{

	{

		$aid = $db->insert_query("attachments", $attacharray);
if($pid)
{

		$aid = $db->insert_query("attachments", $attacharray);
if($pid)
{

Zeile 665Zeile 688
 */
function delete_uploaded_file($path = '')
{

 */
function delete_uploaded_file($path = '')
{

	global $mybb;

	global $mybb, $plugins;


$deleted = false;



$deleted = false;


Zeile 674Zeile 697
	$cdn_base_path = rtrim($mybb->settings['cdnpath'], '/');
$path = ltrim($path, '/');
$cdn_path = realpath($cdn_base_path . '/' . $path);

	$cdn_base_path = rtrim($mybb->settings['cdnpath'], '/');
$path = ltrim($path, '/');
$cdn_path = realpath($cdn_base_path . '/' . $path);



 

if($mybb->settings['usecdn'] && !empty($cdn_base_path))
{
$deleted = $deleted && @unlink($cdn_path);


if($mybb->settings['usecdn'] && !empty($cdn_base_path))
{
$deleted = $deleted && @unlink($cdn_path);

	}








	}

$hook_params = array(
'path' => &$path,
'deleted' => &$deleted,
);

$plugins->run_hooks('delete_uploaded_file', $hook_params);


return $deleted;
}


return $deleted;
}

Zeile 693Zeile 722
 */
function delete_upload_directory($path = '')
{

 */
function delete_upload_directory($path = '')
{

	global $mybb;

	global $mybb, $plugins;


$deleted = false;



$deleted = false;


Zeile 707Zeile 736
	{
$deleted = $deleted && @rmdir($cdn_path);
}

	{
$deleted = $deleted && @rmdir($cdn_path);
}

 

$hook_params = array(
'path' => &$path,
'deleted' => &$deleted,
);

$plugins->run_hooks('delete_upload_directory', $hook_params);


return $deleted;
}


return $deleted;
}

Zeile 729Zeile 765
	{
$upload['error'] = 1;
return $upload;

	{
$upload['error'] = 1;
return $upload;

	}

	}


if(!$filename)
{


if(!$filename)
{

Zeile 740Zeile 776
	$filename = preg_replace("#/$#", "", $filename); // Make the filename safe
$moved = @move_uploaded_file($file['tmp_name'], $path."/".$filename);


	$filename = preg_replace("#/$#", "", $filename); // Make the filename safe
$moved = @move_uploaded_file($file['tmp_name'], $path."/".$filename);


	$moved_cdn = false;
$cdn_base_path = rtrim($mybb->settings['cdnpath'], '/');
$cdn_path = rtrim(realpath($cdn_base_path . '/' . $path), '/');

	$cdn_path = '';







	if($mybb->settings['usecdn'] && !empty($cdn_base_path))
{
$moved_cdn = @copy($path . '/' . $filename, $cdn_path . '/' . $filename);
@my_chmod($cdn_path . '/' . $filename, '0644');
}

	$moved_cdn = copy_file_to_cdn($path."/".$filename, $cdn_path);






if(!$moved)
{


if(!$moved)
{