Vergleich inc/functions_upload.php - 1.8.22 - 1.8.33

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 8Zeile 8
 *
*/


 *
*/


 
/**
* Get maximum upload filesize limit set in PHP
* @since MyBB 1.8.27
* @return int maximum allowed filesize
*/
function get_php_upload_limit()
{
$maxsize = array(return_bytes(ini_get('upload_max_filesize')), return_bytes(ini_get('post_max_size')));
$maxsize = array_filter($maxsize); // Remove empty values

if(empty($maxsize))
{
return 0;
}
else
{
return (int)min($maxsize);
}
}


/**
* Remove an attachment from a specific post


/**
* Remove an attachment from a specific post

Zeile 22Zeile 41
	$aid = (int)$aid;
$posthash = $db->escape_string($posthash);
if(!empty($posthash))

	$aid = (int)$aid;
$posthash = $db->escape_string($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 42Zeile 61

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



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


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

	$uploadspath_abs = mk_path_abs($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.
$query = $db->simple_select("attachments", "COUNT(aid) as numreferences", "attachname='".$db->escape_string($attachment['attachname'])."'");
if($db->fetch_field($query, "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.
$query = $db->simple_select("attachments", "COUNT(aid) as numreferences", "attachname='".$db->escape_string($attachment['attachname'])."'");
if($db->fetch_field($query, "numreferences") == 0)
{

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

		delete_uploaded_file($uploadspath_abs."/".$attachment['attachname']);
if($attachment['thumbnail'] && $attachment['thumbnail'] !== 'SMALL')

		{

		{

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

			delete_uploaded_file($uploadspath_abs."/".$attachment['thumbnail']);

		}

$date_directory = explode('/', $attachment['attachname']);

		}

$date_directory = explode('/', $attachment['attachname']);

		if(@is_dir($uploadpath."/".$date_directory[0]))


		$query_indir = $db->simple_select("attachments", "COUNT(aid) as indir", "attachname LIKE '".$db->escape_string_like($date_directory[0])."/%'");
if($db->fetch_field($query_indir, 'indir') == 0 && @is_dir($uploadspath_abs."/".$date_directory[0]))

		{

		{

			delete_upload_directory($uploadpath."/".$date_directory[0]);

			delete_upload_directory($uploadspath_abs."/".$date_directory[0]);

		}
}

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

		}
}

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

	{
$post = get_post($pid);

	{
$post = get_post($pid);

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

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

Zeile 93Zeile 106
	if($posthash != "" && !$pid)
{
$query = $db->simple_select("attachments", "*", "posthash='$posthash'");

	if($posthash != "" && !$pid)
{
$query = $db->simple_select("attachments", "*", "posthash='$posthash'");

	}
else

	}
else

	{
$query = $db->simple_select("attachments", "*", "pid='$pid'");
}


	{
$query = $db->simple_select("attachments", "*", "pid='$pid'");
}


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


	$uploadspath_abs = mk_path_abs($mybb->settings['uploadspath']);









	$num_attachments = 0;
while($attachment = $db->fetch_array($query))
{
if($attachment['visible'] == 1)
{
$num_attachments++;

	$num_attachments = 0;
while($attachment = $db->fetch_array($query))
{
if($attachment['visible'] == 1)
{
$num_attachments++;

		}


		}


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

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

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

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

		{
delete_uploaded_file($uploadspath_abs."/".$attachment['attachname']);

			if($attachment['thumbnail'])

			if($attachment['thumbnail'])

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

			{
delete_uploaded_file($uploadspath_abs."/".$attachment['thumbnail']);
}


$date_directory = explode('/', $attachment['attachname']);


$date_directory = explode('/', $attachment['attachname']);

			if(@is_dir($uploadpath."/".$date_directory[0]))
{
delete_upload_directory($uploadpath."/".$date_directory[0]);
}


			$query_indir = $db->simple_select("attachments", "COUNT(aid) as indir", "attachname LIKE '".$db->escape_string_like($date_directory[0])."/%'");
if($db->fetch_field($query_indir, 'indir') == 0 && @is_dir($uploadspath_abs."/".$date_directory[0]))
{
delete_upload_directory($uploadspath_abs."/".$date_directory[0]);
}

		}

		}

	}

	}


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 178Zeile 185

@closedir($dir);
}


@closedir($dir);
}

 
}

/**
* Create the attachment directory index file.
*
* @param string $path The path to the attachment directory to create the file in.
*/
function create_attachment_index($path)
{
$index = @fopen(rtrim($path, '/').'/index.html', 'w');
@fwrite($index, '<html>\n<head>\n<title></title>\n</head>\n<body>\n&nbsp;\n</body>\n</html>');
@fclose($index);

}

/**

}

/**

Zeile 198Zeile 217
		$uid = $mybb->user['uid'];
}


		$uid = $mybb->user['uid'];
}


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

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

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

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

Zeile 229Zeile 248

$filename = "avatar_".$uid.".".$ext;
$file = upload_file($avatar, $avatarpath, $filename);


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

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

	}

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

	}

// Check if this is a valid image or not

	}

// Check if this is a valid image or not

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

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

	}


	}


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

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

Zeile 319Zeile 338
		case "image/pjpeg":
case "image/jpg":
$img_type = 2;

		case "image/pjpeg":
case "image/jpg":
$img_type = 2;

			break;

			break;

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

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

Zeile 331Zeile 350
			break;
default:
$img_type = 0;

			break;
default:
$img_type = 0;

	}


	}


	// Check if the uploaded file type matches the correct image type (returned by getimagesize)
if(empty($allowed_mime_types[$avatar['type']]) || $img_dimensions[2] != $img_type || $img_type == 0)
{
$ret['error'] = $lang->error_uploadfailed;

	// Check if the uploaded file type matches the correct image type (returned by getimagesize)
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
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;


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

		return $ret;

	}

// Everything is okay so lets delete old avatars for this user

	}

// Everything is okay so lets delete old avatars for this user

Zeile 360Zeile 379
	$ret = $plugins->run_hooks("upload_avatar_end", $ret);
return $ret;
}

	$ret = $plugins->run_hooks("upload_avatar_end", $ret);
return $ret;
}





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

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

Zeile 374Zeile 393

$posthash = $db->escape_string($mybb->get_input('posthash'));
$pid = (int)$pid;


$posthash = $db->escape_string($mybb->get_input('posthash'));
$pid = (int)$pid;


if(isset($attachment['error']) && $attachment['error'] != 0)
{
$ret['error'] = $lang->error_uploadfailed.$lang->error_uploadfailed_detail;
switch($attachment['error'])
{
case 1: // UPLOAD_ERR_INI_SIZE
$ret['error'] .= $lang->error_uploadfailed_php1;
break;
case 2: // UPLOAD_ERR_FORM_SIZE
$ret['error'] .= $lang->error_uploadfailed_php2;
break;
case 3: // UPLOAD_ERR_PARTIAL
$ret['error'] .= $lang->error_uploadfailed_php3;
break;
case 4: // UPLOAD_ERR_NO_FILE
$ret['error'] .= $lang->error_uploadfailed_php4;
break;
case 6: // UPLOAD_ERR_NO_TMP_DIR
$ret['error'] .= $lang->error_uploadfailed_php6;
break;
case 7: // UPLOAD_ERR_CANT_WRITE
$ret['error'] .= $lang->error_uploadfailed_php7;
break;
default:
$ret['error'] .= $lang->sprintf($lang->error_uploadfailed_phpx, $attachment['error']);
break;
}
return $ret;
}

 

if(!is_uploaded_file($attachment['tmp_name']) || empty($attachment['tmp_name']))
{


if(!is_uploaded_file($attachment['tmp_name']) || empty($attachment['tmp_name']))
{

Zeile 478Zeile 467
	}
$query = $db->simple_select("attachments", "*", "filename='".$db->escape_string($attachment['name'])."' AND ".$uploaded_query);
$prevattach = $db->fetch_array($query);

	}
$query = $db->simple_select("attachments", "*", "filename='".$db->escape_string($attachment['name'])."' AND ".$uploaded_query);
$prevattach = $db->fetch_array($query);

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

	if(!empty($prevattach) && $prevattach['aid'] && $update_attachment == false)

	{
if(!$mybb->usergroup['caneditattachments'] && !$forumpermissions['caneditattachments'])
{

	{
if(!$mybb->usergroup['caneditattachments'] && !$forumpermissions['caneditattachments'])
{

Zeile 502Zeile 491
		}
}


		}
}


 
	$uploadspath_abs = mk_path_abs($mybb->settings['uploadspath']);

	$month_dir = '';
if($mybb->safemode == false)
{
// Check if the attachment directory (YYYYMM) exists, if not, create it
$month_dir = gmdate("Ym");

	$month_dir = '';
if($mybb->safemode == false)
{
// Check if the attachment directory (YYYYMM) exists, if not, create it
$month_dir = gmdate("Ym");

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

		if(!@is_dir($uploadspath_abs."/".$month_dir))

		{

		{

			@mkdir($mybb->settings['uploadspath']."/".$month_dir);

			@mkdir($uploadspath_abs."/".$month_dir);

			// Still doesn't exist - oh well, throw it in the main directory

			// Still doesn't exist - oh well, throw it in the main directory

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

			if(!@is_dir($uploadspath_abs."/".$month_dir))

			{
$month_dir = '';
}
else
{

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

				create_attachment_index($uploadspath_abs."/".$month_dir);



			}
}
}

			}
}
}

Zeile 527Zeile 515
	// All seems to be good, lets move the attachment!
$filename = "post_".$mybb->user['uid']."_".TIME_NOW."_".md5(random_str()).".attach";


	// All seems to be good, lets move the attachment!
$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, $uploadspath_abs."/".$month_dir, $filename);


// Failed to create the attachment in the monthly directory, just throw it in the main directory
if(!empty($file['error']) && $month_dir)
{


// Failed to create the attachment in the monthly directory, just throw it in the main directory
if(!empty($file['error']) && $month_dir)
{

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

		$file = upload_file($attachment, $uploadspath_abs.'/', $filename);
}
elseif($month_dir)
{

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


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


Zeile 555Zeile 543
	}

// Lets just double check that it exists

	}

// Lets just double check that it exists

	if(!file_exists($mybb->settings['uploadspath']."/".$filename))

	if(!file_exists($uploadspath_abs."/".$filename))

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

Zeile 573Zeile 561
		"downloads" => 0,
"dateuploaded" => TIME_NOW
);

		"downloads" => 0,
"dateuploaded" => TIME_NOW
);





	// If we're uploading an image, check the MIME type compared to the image type and attempt to generate a thumbnail
if($ext == "gif" || $ext == "png" || $ext == "jpg" || $ext == "jpeg" || $ext == "jpe")
{

	// If we're uploading an image, check the MIME type compared to the image type and attempt to generate a thumbnail
if($ext == "gif" || $ext == "png" || $ext == "jpg" || $ext == "jpeg" || $ext == "jpe")
{

Zeile 608Zeile 596
		}

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

		$img_dimensions = @getimagesize($mybb->settings['uploadspath']."/".$filename);

		$img_dimensions = @getimagesize($uploadspath_abs."/".$filename);


$mime = "";


$mime = "";

		$file_path = $mybb->settings['uploadspath']."/".$filename;

		$file_path = $uploadspath_abs."/".$filename;

		if(function_exists("finfo_open"))
{
$file_info = finfo_open(FILEINFO_MIME);

		if(function_exists("finfo_open"))
{
$file_info = finfo_open(FILEINFO_MIME);

			list($mime, ) = explode(';', finfo_file($file_info, MYBB_ROOT.$file_path), 1);

			list($mime, ) = explode(';', finfo_file($file_info, $file_path), 1);

			finfo_close($file_info);
}
else if(function_exists("mime_content_type"))
{

			finfo_close($file_info);
}
else if(function_exists("mime_content_type"))
{

			$mime = mime_content_type(MYBB_ROOT.$file_path);

			$mime = mime_content_type($file_path);

		}

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

		}

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

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

			delete_uploaded_file($uploadspath_abs."/".$filename);

			$ret['error'] = $lang->error_uploadfailed;
return $ret;
}

			$ret['error'] = $lang->error_uploadfailed;
return $ret;
}

Zeile 634Zeile 622

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



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


		$thumbnail = generate_thumbnail($mybb->settings['uploadspath']."/".$filename, $mybb->settings['uploadspath'], $thumbname, $mybb->settings['attachthumbh'], $mybb->settings['attachthumbw']);

		$thumbnail = generate_thumbnail($uploadspath_abs."/".$filename, $uploadspath_abs, $thumbname, $mybb->settings['attachthumbh'], $mybb->settings['attachthumbw']);





		if($thumbnail['filename'])

		if(!empty($thumbnail['filename']))

		{
$attacharray['thumbnail'] = $thumbnail['filename'];
}
elseif($thumbnail['code'] == 4)

		{
$attacharray['thumbnail'] = $thumbnail['filename'];
}
elseif($thumbnail['code'] == 4)

		{

		{

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

			$attacharray['thumbnail'] = "SMALL";
}
}
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);

	}

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





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

	if(!empty($prevattach) && $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 666Zeile 654
		$query = $db->simple_select("attachments", "COUNT(aid) as numreferences", "attachname='".$db->escape_string($prevattach['attachname'])."'");
if($db->fetch_field($query, "numreferences") == 0)
{

		$query = $db->simple_select("attachments", "COUNT(aid) as numreferences", "attachname='".$db->escape_string($prevattach['attachname'])."'");
if($db->fetch_field($query, "numreferences") == 0)
{

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

			delete_uploaded_file($uploadspath_abs."/".$prevattach['attachname']);

			if($prevattach['thumbnail'])

			if($prevattach['thumbnail'])

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

			{
delete_uploaded_file($uploadspath_abs."/".$prevattach['thumbnail']);

			}

$date_directory = explode('/', $prevattach['attachname']);

			}

$date_directory = explode('/', $prevattach['attachname']);

			if(@is_dir($mybb->settings['uploadspath']."/".$date_directory[0]))


			$query_indir = $db->simple_select("attachments", "COUNT(aid) as indir", "attachname LIKE '".$db->escape_string_like($date_directory[0])."/%'");
if($db->fetch_field($query_indir, 'indir') == 0 && @is_dir($uploadspath_abs."/".$date_directory[0]))

			{

			{

				delete_upload_directory($mybb->settings['uploadspath']."/".$date_directory[0]);

				delete_upload_directory($uploadspath_abs."/".$date_directory[0]);

			}
}


			}
}


Zeile 694Zeile 683
}

/**

}

/**

 * Process adding attachment(s) when the "Add Attachment" button is pressed.















































 * Check whether the input $FILE variable indicates a PHP file upload error,
* and if so, return an appropriate user-friendly error message.
*
* @param array $FILE File data (as fed by PHP's $_FILE).
*
* @return string Error message or empty if no error detected.
*/
function check_parse_php_upload_err($FILE)
{
global $lang;

$err = '';

if(isset($FILE['error']) && $FILE['error'] != 0 && ($FILE['error'] != UPLOAD_ERR_NO_FILE || $FILE['name']))
{
$err = $lang->error_uploadfailed.$lang->error_uploadfailed_detail;
switch($FILE['error'])
{
case 1: // UPLOAD_ERR_INI_SIZE
$err .= $lang->error_uploadfailed_php1;
break;
case 2: // UPLOAD_ERR_FORM_SIZE
$err .= $lang->error_uploadfailed_php2;
break;
case 3: // UPLOAD_ERR_PARTIAL
$err .= $lang->error_uploadfailed_php3;
break;
case 4: // UPLOAD_ERR_NO_FILE
$err .= $lang->error_uploadfailed_php4;
break;
case 6: // UPLOAD_ERR_NO_TMP_DIR
$err .= $lang->error_uploadfailed_php6;
break;
case 7: // UPLOAD_ERR_CANT_WRITE
$err .= $lang->error_uploadfailed_php7;
break;
default:
$err .= $lang->sprintf($lang->error_uploadfailed_phpx, $FILE['error']);
break;
}
}

return $err;
}

/**
* 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 int $pid The ID of the post.
* @param array $forumpermission The permissions for the forum.

Zeile 708Zeile 743
	global $db, $mybb, $editdraftpid, $lang;

$ret = array();

	global $db, $mybb, $editdraftpid, $lang;

$ret = array();





	if($forumpermissions['canpostattachments'])
{
$attachments = array();

	if($forumpermissions['canpostattachments'])
{
$attachments = array();

Zeile 722Zeile 757
		{
foreach($fields as $field)
{

		{
foreach($fields as $field)
{

				$attach1[$field] = $_FILES['attachments'][$field][$key];

 
				$attachments[$i][$field] = $_FILES['attachments'][$field][$i];
}


				$attachments[$i][$field] = $_FILES['attachments'][$field][$i];
}


Zeile 731Zeile 765
			{
$filenames .= $delim . "'" . $db->escape_string($FILE['name']) . "'";
$delim = ",";

			{
$filenames .= $delim . "'" . $db->escape_string($FILE['name']) . "'";
$delim = ",";

			}
}


			}
}


		if ($filenames != '')

		if ($filenames != '')

		{

		{

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

while ($row = $db->fetch_array($query))

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

while ($row = $db->fetch_array($query))

			{

			{

				$aid[$row['filename']] = true;

				$aid[$row['filename']] = true;

			}

			}

		}

foreach($attachments as $FILE)
{

		}

foreach($attachments as $FILE)
{

			if(!empty($FILE['name']) && !empty($FILE['type']))






			if($err = check_parse_php_upload_err($FILE))
{
$ret['errors'][] = $err;
$mybb->input['action'] = $action;
}
else if(!empty($FILE['name']) && !empty($FILE['type']))

			{
if($FILE['size'] > 0)
{
$filename = $db->escape_string($FILE['name']);

			{
if($FILE['size'] > 0)
{
$filename = $db->escape_string($FILE['name']);

					$exists = $aid[$filename];

					$exists = !empty($aid[$filename]);


$update_attachment = false;
if($action == "editpost")


$update_attachment = false;
if($action == "editpost")

Zeile 768Zeile 807
							$update_attachment = true;
}
}

							$update_attachment = true;
}
}


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

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

					
if(!$exists && $mybb->get_input('updateattachment') && $mybb->get_input('updateconfirmed', MyBB::INPUT_INT) != 1)



					{

					{

						$ret['errors'][] = $attachedfile['error'];
$mybb->input['action'] = $action;














						$ret['errors'][] = $lang->sprintf($lang->error_updatefailed, $filename);
}
else
{
$attachedfile = upload_attachment($FILE, $update_attachment);

if(!empty($attachedfile['error']))
{
$ret['errors'][] = $attachedfile['error'];
$mybb->input['action'] = $action;
}
else if(isset($attachedfile['aid']) && $mybb->get_input('ajax', MyBB::INPUT_INT) == 1)
{
$ret['success'][] = array($attachedfile['aid'], get_attachment_icon(get_extension($filename)), htmlspecialchars_uni($filename), get_friendly_size($FILE['size']));
}

					}
}
else

					}
}
else

Zeile 791Zeile 841

/**
* Delete an uploaded file both from the relative path and the CDN path if a CDN is in use.


/**
* Delete an uploaded file both from the relative path and the CDN path if a CDN is in use.

 *

 *

 * @param string $path The relative path to the uploaded file.
*
* @return bool Whether the file was deleted successfully.
*/
function delete_uploaded_file($path = '')

 * @param string $path The relative path to the uploaded file.
*
* @return bool Whether the file was deleted successfully.
*/
function delete_uploaded_file($path = '')

{
global $mybb, $plugins;

$deleted = false;

$deleted = @unlink($path);

{
global $mybb, $plugins;

$deleted = false;

$deleted = @unlink($path);


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

	if(!empty($mybb->settings['usecdn']) && !empty($cdn_base_path))

	{
$deleted = $deleted && @unlink($cdn_path);

	{
$deleted = $deleted && @unlink($cdn_path);

	}


	}


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

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





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

return $deleted;
}

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

return $deleted;
}





/**
* Delete an upload directory on both the local filesystem and the CDN filesystem.
*

/**
* Delete an upload directory on both the local filesystem and the CDN filesystem.
*

Zeile 835Zeile 885
	global $mybb, $plugins;

$deleted = false;

	global $mybb, $plugins;

$deleted = false;

 

$deleted_index = @unlink(rtrim($path, '/').'/index.html');


$deleted = @rmdir($path);


$deleted = @rmdir($path);





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

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


if($mybb->settings['usecdn'] && !empty($cdn_base_path))
{


if(!empty($mybb->settings['usecdn']) && !empty($cdn_base_path))
{

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

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

	}


	}


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

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





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

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

 

// If not successfully deleted then reinstante the index file
if(!$deleted && $deleted_index)
{
create_attachment_index($path);
}


return $deleted;
}


return $deleted;
}