Vergleich inc/functions_upload.php - 1.8.10 - 1.8.22

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 21Zeile 21
	global $db, $mybb, $plugins;
$aid = (int)$aid;
$posthash = $db->escape_string($posthash);

	global $db, $mybb, $plugins;
$aid = (int)$aid;
$posthash = $db->escape_string($posthash);

	if($posthash != "")

	if(!empty($posthash))

	{
$query = $db->simple_select("attachments", "aid, attachname, thumbnail, visible", "aid='{$aid}' AND posthash='{$posthash}'");
$attachment = $db->fetch_array($query);

	{
$query = $db->simple_select("attachments", "aid, attachname, thumbnail, visible", "aid='{$aid}' AND posthash='{$posthash}'");
$attachment = $db->fetch_array($query);

Zeile 34Zeile 34

$plugins->run_hooks("remove_attachment_do_delete", $attachment);



$plugins->run_hooks("remove_attachment_do_delete", $attachment);


	$db->delete_query("attachments", "aid='{$attachment['aid']}'");

if(defined('IN_ADMINCP'))
{
$uploadpath = '../'.$mybb->settings['uploadspath'];
}
else

	if($attachment === false)







	{

	{

	    $uploadpath = $mybb->settings['uploadspath'];













		// no attachment found with the given details
return;
}

$db->delete_query("attachments", "aid='{$attachment['aid']}'");

if(defined('IN_ADMINCP'))
{
$uploadpath = '../'.$mybb->settings['uploadspath'];
}
else
{
$uploadpath = $mybb->settings['uploadspath'];

	}

// Check if this attachment is referenced in any other posts. If it isn't, then we are safe to delete the actual file.

	}

// Check if this attachment is referenced in any other posts. If it isn't, then we are safe to delete the actual file.

Zeile 53Zeile 59
		if($attachment['thumbnail'])
{
delete_uploaded_file($uploadpath."/".$attachment['thumbnail']);

		if($attachment['thumbnail'])
{
delete_uploaded_file($uploadpath."/".$attachment['thumbnail']);

		}

		}


$date_directory = explode('/', $attachment['attachname']);
if(@is_dir($uploadpath."/".$date_directory[0]))


$date_directory = explode('/', $attachment['attachname']);
if(@is_dir($uploadpath."/".$date_directory[0]))

Zeile 63Zeile 69
	}

if($attachment['visible'] == 1 && $pid)

	}

if($attachment['visible'] == 1 && $pid)

	{

	{

		$post = get_post($pid);
update_thread_counters($post['tid'], array("attachmentcount" => "-1"));
}

		$post = get_post($pid);
update_thread_counters($post['tid'], array("attachmentcount" => "-1"));
}

Zeile 113Zeile 119
		$plugins->run_hooks("remove_attachments_do_delete", $attachment);

$db->delete_query("attachments", "aid='".$attachment['aid']."'");

		$plugins->run_hooks("remove_attachments_do_delete", $attachment);

$db->delete_query("attachments", "aid='".$attachment['aid']."'");





		// Check if this attachment is referenced in any other posts. If it isn't, then we are safe to delete the actual file.
$query2 = $db->simple_select("attachments", "COUNT(aid) as numreferences", "attachname='".$db->escape_string($attachment['attachname'])."'");
if($db->fetch_field($query2, "numreferences") == 0)

		// Check if this attachment is referenced in any other posts. If it isn't, then we are safe to delete the actual file.
$query2 = $db->simple_select("attachments", "COUNT(aid) as numreferences", "attachname='".$db->escape_string($attachment['attachname'])."'");
if($db->fetch_field($query2, "numreferences") == 0)

Zeile 122Zeile 128
			if($attachment['thumbnail'])
{
delete_uploaded_file($uploadpath."/".$attachment['thumbnail']);

			if($attachment['thumbnail'])
{
delete_uploaded_file($uploadpath."/".$attachment['thumbnail']);

			}


			}


			$date_directory = explode('/', $attachment['attachname']);
if(@is_dir($uploadpath."/".$date_directory[0]))
{

			$date_directory = explode('/', $attachment['attachname']);
if(@is_dir($uploadpath."/".$date_directory[0]))
{

Zeile 133Zeile 139
	}

if($post['tid'])

	}

if($post['tid'])

	{

	{

		update_thread_counters($post['tid'], array("attachmentcount" => "-{$num_attachments}"));
}
}

		update_thread_counters($post['tid'], array("attachmentcount" => "-{$num_attachments}"));
}
}

Zeile 143Zeile 149
 *
* @param int $uid The user ID
* @param string $exclude A file name to be excluded from the removal

 *
* @param int $uid The user ID
* @param string $exclude A file name to be excluded from the removal

 */

 */

function remove_avatars($uid, $exclude="")
{
global $mybb, $plugins;

function remove_avatars($uid, $exclude="")
{
global $mybb, $plugins;

Zeile 153Zeile 159
		$avatarpath = '../'.$mybb->settings['avataruploadpath'];
}
else

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

	{

	{

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


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


Zeile 163Zeile 169
		while($file = @readdir($dir))
{
$plugins->run_hooks("remove_avatars_do_delete", $file);

		while($file = @readdir($dir))
{
$plugins->run_hooks("remove_avatars_do_delete", $file);





			if(preg_match("#avatar_".$uid."\.#", $file) && is_file($avatarpath."/".$file) && $file != $exclude)
{
delete_uploaded_file($avatarpath."/".$file);

			if(preg_match("#avatar_".$uid."\.#", $file) && is_file($avatarpath."/".$file) && $file != $exclude)
{
delete_uploaded_file($avatarpath."/".$file);

Zeile 173Zeile 179
		@closedir($dir);
}
}

		@closedir($dir);
}
}





/**
* Upload a new avatar in to the file system
*

/**
* Upload a new avatar in to the file system
*

Zeile 193Zeile 199
	}

if(!$avatar['name'] || !$avatar['tmp_name'])

	}

if(!$avatar['name'] || !$avatar['tmp_name'])

	{

	{

		$avatar = $_FILES['avatarupload'];
}

		$avatar = $_FILES['avatarupload'];
}


if(!is_uploaded_file($avatar['tmp_name']))
{
$ret['error'] = $lang->error_uploadfailed;
return $ret;
}


if(!is_uploaded_file($avatar['tmp_name']))
{
$ret['error'] = $lang->error_uploadfailed;
return $ret;
}


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


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

Zeile 212Zeile 218
    	}

if(defined('IN_ADMINCP'))

    	}

if(defined('IN_ADMINCP'))

	{

	{

		$avatarpath = '../'.$mybb->settings['avataruploadpath'];
$lang->load("messages", true);
}

		$avatarpath = '../'.$mybb->settings['avataruploadpath'];
$lang->load("messages", true);
}

Zeile 232Zeile 238

// Lets just double check that it exists
if(!file_exists($avatarpath."/".$filename))


// Lets just double check that it exists
if(!file_exists($avatarpath."/".$filename))

	{

	{

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

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

Zeile 250Zeile 256
	// 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 273Zeile 279
					$avatar['size'] = filesize($avatarpath."/".$filename);
// Reset dimensions
$img_dimensions = @getimagesize($avatarpath."/".$filename);

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

				}
}

				}
}

			else
{
$ret['error'] = $lang->sprintf($lang->error_avatartoobig, $maxwidth, $maxheight);

			else
{
$ret['error'] = $lang->sprintf($lang->error_avatartoobig, $maxwidth, $maxheight);

Zeile 331Zeile 337
	if(empty($allowed_mime_types[$avatar['type']]) || $img_dimensions[2] != $img_type || $img_type == 0)
{
$ret['error'] = $lang->error_uploadfailed;

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


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


	// Next check the file size

	// 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))

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

	{
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);





	$ret = array(
"avatar" => $mybb->settings['avataruploadpath']."/".$filename,
"width" => (int)$img_dimensions[0],
"height" => (int)$img_dimensions[1]
);
$ret = $plugins->run_hooks("upload_avatar_end", $ret);

	$ret = array(
"avatar" => $mybb->settings['avataruploadpath']."/".$filename,
"width" => (int)$img_dimensions[0],
"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 402Zeile 408
	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;
}


		return $ret;
}


    $attachtypes = (array)$cache->read('attachtypes');
$attachment = $plugins->run_hooks("upload_attachment_start", $attachment);


    $attachtypes = (array)$cache->read('attachtypes');
$attachment = $plugins->run_hooks("upload_attachment_start", $attachment);


Zeile 429Zeile 435
		$attachtype = $attachtypes[$ext];
}


		$attachtype = $attachtypes[$ext];
}


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


	// check the length of the filename
$maxFileNameLength = 255;
if(my_strlen($attachment['name']) > $maxFileNameLength)

	{

	{

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








		$ret['error'] = $lang->sprintf($lang->error_attach_filename_length, htmlspecialchars_uni($attachment['name']), $maxFileNameLength);
return $ret;
}

// Check the size
if($attachment['size'] > $attachtype['maxsize']*1024 && $attachtype['maxsize'] != "")
{
$ret['error'] = $lang->sprintf($lang->error_attachsize, htmlspecialchars_uni($attachment['name']), $attachtype['maxsize']);

		return $ret;
}


		return $ret;
}


Zeile 472Zeile 486
			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 676Zeile 690
		}
}
$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;
}