Vergleich inc/functions_upload.php - 1.8.5 - 1.8.20

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 250Zeile 250
	// Check avatar dimensions
if($mybb->settings['maxavatardims'] != '')
{

	// Check avatar dimensions
if($mybb->settings['maxavatardims'] != '')
{

		list($maxwidth, $maxheight) = @explode("x", $mybb->settings['maxavatardims']);

		list($maxwidth, $maxheight) = @preg_split('/[|x]/', $mybb->settings['maxavatardims']);

		if(($maxwidth && $img_dimensions[0] > $maxwidth) || ($maxheight && $img_dimensions[1] > $maxheight))
{
// Automatic resizing enabled?

		if(($maxwidth && $img_dimensions[0] > $maxwidth) || ($maxheight && $img_dimensions[1] > $maxheight))
{
// Automatic resizing enabled?

Zeile 286Zeile 286
				return $ret;
}
}

				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 312Zeile 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;
}

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

			break;
default:
$img_type = 0;
}

// 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(($mybb->settings['avatarsize'] > 0 && $avatar['size'] > ($mybb->settings['avatarsize']*1024)) || $avatar['size'] > ($allowed_mime_types[$avatar['type']]*1024))
{
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 333Zeile 352
		"height" => (int)$img_dimensions[1]
);
$ret = $plugins->run_hooks("upload_avatar_end", $ret);

		"height" => (int)$img_dimensions[1]
);
$ret = $plugins->run_hooks("upload_avatar_end", $ret);

	return $ret;
}

	return $ret;
}


/**
* Upload an attachment in to the file system


/**
* Upload an attachment in to the file system

Zeile 369Zeile 388
				break;
case 6: // UPLOAD_ERR_NO_TMP_DIR
$ret['error'] .= $lang->error_uploadfailed_php6;

				break;
case 6: // UPLOAD_ERR_NO_TMP_DIR
$ret['error'] .= $lang->error_uploadfailed_php6;

				break;

				break;

			case 7: // UPLOAD_ERR_CANT_WRITE
$ret['error'] .= $lang->error_uploadfailed_php7;

			case 7: // UPLOAD_ERR_CANT_WRITE
$ret['error'] .= $lang->error_uploadfailed_php7;

				break;

				break;

			default:
$ret['error'] .= $lang->sprintf($lang->error_uploadfailed_phpx, $attachment['error']);

			default:
$ret['error'] .= $lang->sprintf($lang->error_uploadfailed_phpx, $attachment['error']);

				break;
}
return $ret;

				break;
}
return $ret;

	}

if(!is_uploaded_file($attachment['tmp_name']) || empty($attachment['tmp_name']))
{
$ret['error'] = $lang->error_uploadfailed.$lang->error_uploadfailed_php4;

	}

if(!is_uploaded_file($attachment['tmp_name']) || empty($attachment['tmp_name']))
{
$ret['error'] = $lang->error_uploadfailed.$lang->error_uploadfailed_php4;

		return $ret;
}

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

		return $ret;
}

$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
if(!isset($attachtypes[$ext]))
{
$ret['error'] = $lang->error_attachtype;


$ext = get_extension($attachment['name']);
// Check if we have a valid extension
if(!isset($attachtypes[$ext]))
{
$ret['error'] = $lang->error_attachtype;

		return $ret;
}

		return $ret;
}

	else
{
$attachtype = $attachtypes[$ext];

	else
{
$attachtype = $attachtypes[$ext];

	}


	}


	// Check the size
if($attachment['size'] > $attachtype['maxsize']*1024 && $attachtype['maxsize'] != "")
{

	// Check the size
if($attachment['size'] > $attachtype['maxsize']*1024 && $attachtype['maxsize'] != "")
{

		$ret['error'] = $lang->sprintf($lang->error_attachsize, $attachtype['maxsize']);

		$ret['error'] = $lang->sprintf($lang->error_attachsize, htmlspecialchars_uni($attachment['name']), $attachtype['maxsize']);

		return $ret;

		return $ret;

	}


	}


	// Double check attachment space usage
if($mybb->usergroup['attachquota'] > 0)
{

	// Double check attachment space usage
if($mybb->usergroup['attachquota'] > 0)
{

Zeile 423Zeile 451
	}

// Gather forum permissions

	}

// Gather forum permissions

	$forumpermissions = forum_permissions($forum['fid']);

	$forumpermissions = forum_permissions($forum['fid']);


// Check if an attachment with this name is already in the post
if($pid != 0)


// Check if an attachment with this name is already in the post
if($pid != 0)

Zeile 444Zeile 472
			return $ret;
}


			return $ret;
}


		$ret['error'] = $lang->error_alreadyuploaded;

		$ret['error'] = $lang->sprintf($lang->error_alreadyuploaded, htmlspecialchars_uni($attachment['name']));

		return $ret;
}


		return $ret;
}


Zeile 472Zeile 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);

			}
}
}

// All seems to be good, lets move the attachment!

			}
}
}

// All seems to be good, lets move the attachment!

	$filename = "post_".$mybb->user['uid']."_".TIME_NOW."_".md5(random_str()).".attach";

	$filename = "post_".$mybb->user['uid']."_".TIME_NOW."_".md5(random_str()).".attach";


$file = upload_file($attachment, $mybb->settings['uploadspath']."/".$month_dir, $filename);



$file = upload_file($attachment, $mybb->settings['uploadspath']."/".$month_dir, $filename);


Zeile 487Zeile 521
		$file = upload_file($attachment, $mybb->settings['uploadspath'].'/', $filename);
}
elseif($month_dir)

		$file = upload_file($attachment, $mybb->settings['uploadspath'].'/', $filename);
}
elseif($month_dir)

	{

	{

		$filename = $month_dir."/".$filename;
}

if(!empty($file['error']))

		$filename = $month_dir."/".$filename;
}

if(!empty($file['error']))

	{

	{

		$ret['error'] = $lang->error_uploadfailed.$lang->error_uploadfailed_detail;
switch($file['error'])
{

		$ret['error'] = $lang->error_uploadfailed.$lang->error_uploadfailed_detail;
switch($file['error'])
{

Zeile 511Zeile 545
	{
$ret['error'] = $lang->error_uploadfailed.$lang->error_uploadfailed_detail.$lang->error_uploadfailed_lost;
return $ret;

	{
$ret['error'] = $lang->error_uploadfailed.$lang->error_uploadfailed_detail.$lang->error_uploadfailed_lost;
return $ret;

	}

	}


// Generate the array for the insert_query
$attacharray = array(


// Generate the array for the insert_query
$attacharray = array(

Zeile 554Zeile 588
		foreach($attachtypes as $attachtype)
{
if(!empty($attachtype['mimetype']))

		foreach($attachtypes as $attachtype)
{
if(!empty($attachtype['mimetype']))

			{

			{

				$supported_mimes[] = $attachtype['mimetype'];
}
}

				$supported_mimes[] = $attachtype['mimetype'];
}
}

Zeile 565Zeile 599
		$mime = "";
$file_path = $mybb->settings['uploadspath']."/".$filename;
if(function_exists("finfo_open"))

		$mime = "";
$file_path = $mybb->settings['uploadspath']."/".$filename;
if(function_exists("finfo_open"))

		{

		{

			$file_info = finfo_open(FILEINFO_MIME);
list($mime, ) = explode(';', finfo_file($file_info, MYBB_ROOT.$file_path), 1);
finfo_close($file_info);
}
else if(function_exists("mime_content_type"))

			$file_info = finfo_open(FILEINFO_MIME);
list($mime, ) = explode(';', finfo_file($file_info, MYBB_ROOT.$file_path), 1);
finfo_close($file_info);
}
else if(function_exists("mime_content_type"))

		{

		{

			$mime = mime_content_type(MYBB_ROOT.$file_path);
}

if(!is_array($img_dimensions) || ($img_dimensions[2] != $img_type && !in_array($mime, $supported_mimes)))

			$mime = mime_content_type(MYBB_ROOT.$file_path);
}

if(!is_array($img_dimensions) || ($img_dimensions[2] != $img_type && !in_array($mime, $supported_mimes)))

		{

		{

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

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

Zeile 598Zeile 632
		}
}
if($forumpermissions['modattachments'] == 1 && !is_moderator($forum['fid'], "canapproveunapproveattachs"))

		}
}
if($forumpermissions['modattachments'] == 1 && !is_moderator($forum['fid'], "canapproveunapproveattachs"))

	{

	{

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

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

	}


	}


	$attacharray = $plugins->run_hooks("upload_attachment_do_insert", $attacharray);

if($prevattach['aid'] && $update_attachment == true)

	$attacharray = $plugins->run_hooks("upload_attachment_do_insert", $attacharray);

if($prevattach['aid'] && $update_attachment == true)

	{

	{

		unset($attacharray['downloads']); // Keep our download count if we're updating an attachment
$db->update_query("attachments", $attacharray, "aid='".$db->escape_string($prevattach['aid'])."'");


		unset($attacharray['downloads']); // Keep our download count if we're updating an attachment
$db->update_query("attachments", $attacharray, "aid='".$db->escape_string($prevattach['aid'])."'");


Zeile 620Zeile 654
		{
delete_uploaded_file($mybb->settings['uploadspath']."/".$prevattach['attachname']);
if($prevattach['thumbnail'])

		{
delete_uploaded_file($mybb->settings['uploadspath']."/".$prevattach['attachname']);
if($prevattach['thumbnail'])

			{

			{

				delete_uploaded_file($mybb->settings['uploadspath']."/".$prevattach['thumbnail']);
}


				delete_uploaded_file($mybb->settings['uploadspath']."/".$prevattach['thumbnail']);
}


Zeile 642Zeile 676
		}
}
$ret['aid'] = $aid;

		}
}
$ret['aid'] = $aid;

 
	return $ret;
}

/**
* Process adding attachment(s) when the "Add Attachment" button is pressed.
*
* @param int $pid The ID of the post.
* @param array $forumpermission The permissions for the forum.
* @param string $attachwhere Search string "pid='$pid'" or "posthash='".$db->escape_string($mybb->get_input('posthash'))."'"
* @param string $action Where called from: "newthread", "newreply", or "editpost"
*
* @return array Array of errors if any, empty array otherwise
*/
function add_attachments($pid, $forumpermissions, $attachwhere, $action=false)
{
global $db, $mybb, $editdraftpid, $lang;

$ret = array();

if($forumpermissions['canpostattachments'])
{
$attachments = array();
$fields = array ('name', 'type', 'tmp_name', 'error', 'size');
$aid = array();

$total = isset($_FILES['attachments']['name']) ? count($_FILES['attachments']['name']) : 0;
$filenames = "";
$delim = "";
for($i=0; $i<$total; ++$i)
{
foreach($fields as $field)
{
$attach1[$field] = $_FILES['attachments'][$field][$key];
$attachments[$i][$field] = $_FILES['attachments'][$field][$i];
}

$FILE = $attachments[$i];
if(!empty($FILE['name']) && !empty($FILE['type']) && $FILE['size'] > 0)
{
$filenames .= $delim . "'" . $db->escape_string($FILE['name']) . "'";
$delim = ",";
}
}

if ($filenames != '')
{
$query = $db->simple_select("attachments", "filename", "{$attachwhere} AND filename IN (".$filenames.")");

while ($row = $db->fetch_array($query))
{
$aid[$row['filename']] = true;
}
}

foreach($attachments as $FILE)
{
if(!empty($FILE['name']) && !empty($FILE['type']))
{
if($FILE['size'] > 0)
{
$filename = $db->escape_string($FILE['name']);
$exists = $aid[$filename];

$update_attachment = false;
if($action == "editpost")
{
if($exists && $mybb->get_input('updateattachment') && ($mybb->usergroup['caneditattachments'] || $forumpermissions['caneditattachments']))
{
$update_attachment = true;
}
}
else
{
if($exists && $mybb->get_input('updateattachment'))
{
$update_attachment = true;
}
}

$attachedfile = upload_attachment($FILE, $update_attachment);

if(!empty($attachedfile['error']))
{
$ret['errors'][] = $attachedfile['error'];
$mybb->input['action'] = $action;
}
}
else
{
$ret['errors'][] = $lang->sprintf($lang->error_uploadempty, htmlspecialchars_uni($FILE['name']));
$mybb->input['action'] = $action;
}
}
}
}


	return $ret;
}


	return $ret;
}