Vergleich inc/functions_upload.php - 1.8.1 - 1.8.23

  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 33Zeile 33
	}

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

	}

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

 

if($attachment === false)
{
// no attachment found with the given details
return;
}


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



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


Zeile 199Zeile 205

if(!is_uploaded_file($avatar['tmp_name']))
{


if(!is_uploaded_file($avatar['tmp_name']))
{

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

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

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






















		return $ret;
}

		return $ret;
}

 

// Check we have a valid extension
$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 245Zeile 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 263Zeile 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 280Zeile 273
				}
else
{

				}
else
{

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

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

					// Reset filesize
$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 295Zeile 290
				}
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
$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'];
}
}





	// Check a list of known MIME types to establish what kind of avatar we're uploading
switch(my_strtolower($avatar['type']))


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

switch($avatar['type'])

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

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

Zeile 323Zeile 323
		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 360Zeile 374

$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']))
{
$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');
$attachment = $plugins->run_hooks("upload_attachment_start", $attachment);











		return $ret;
}

$attachtypes = (array)$cache->read('attachtypes');
$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;
}
else
{
$attachtype = $attachtypes[$ext];
}









		return $ret;
}
else
{
$attachtype = $attachtypes[$ext];
}

// check the length of the filename
$maxFileNameLength = 255;
if(my_strlen($attachment['name']) > $maxFileNameLength)
{
$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'] != "")
{


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

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

		return $ret;
}

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

	{

	{

		$query = $db->simple_select("attachments", "SUM(filesize) AS ausage", "uid='".$mybb->user['uid']."'");
$usage = $db->fetch_array($query);
$usage = $usage['ausage']+$attachment['size'];

		$query = $db->simple_select("attachments", "SUM(filesize) AS ausage", "uid='".$mybb->user['uid']."'");
$usage = $db->fetch_array($query);
$usage = $usage['ausage']+$attachment['size'];

Zeile 429Zeile 430
		{
$friendlyquota = get_friendly_size($mybb->usergroup['attachquota']*1024);
$ret['error'] = $lang->sprintf($lang->error_reachedattachquota, $friendlyquota);

		{
$friendlyquota = get_friendly_size($mybb->usergroup['attachquota']*1024);
$ret['error'] = $lang->sprintf($lang->error_reachedattachquota, $friendlyquota);

			return $ret;
}
}

			return $ret;
}
}


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


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

Zeile 455Zeile 456
			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 483Zeile 484
			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 571Zeile 578
		}

// 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($mybb->settings['uploadspath']."/".$filename);


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

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

Zeile 594Zeile 601
		}
require_once MYBB_ROOT."inc/functions_image.php";
$thumbname = str_replace(".attach", "_thumb.$ext", $filename);

		}
require_once MYBB_ROOT."inc/functions_image.php";
$thumbname = str_replace(".attach", "_thumb.$ext", $filename);





		$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']);

		$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']);

Zeile 615Zeile 622
	else
{
$attacharray['visible'] = 1;

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

	}

	}


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



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


Zeile 637Zeile 644

$date_directory = explode('/', $prevattach['attachname']);
if(@is_dir($mybb->settings['uploadspath']."/".$date_directory[0]))


$date_directory = explode('/', $prevattach['attachname']);
if(@is_dir($mybb->settings['uploadspath']."/".$date_directory[0]))

			{

			{

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

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

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

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

		{

		{

			update_thread_counters($tid, array("attachmentcount" => "+1"));
}
}

			update_thread_counters($tid, array("attachmentcount" => "+1"));
}
}

	$ret['aid'] = $aid;




















































































































































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

/**
* 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 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)
{
$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($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']);
$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;
}

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

	return $ret;
}

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


	global $mybb, $plugins;


	$deleted = false;

$deleted = @unlink($path);

	$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))
{
$deleted = $deleted && @unlink($cdn_path);

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

	}

return $deleted;








	}

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

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

return $deleted;

}

/**

}

/**

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

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

	global $mybb;

	global $mybb, $plugins;


$deleted = false;



$deleted = false;


Zeile 707Zeile 867
	{
$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 724Zeile 891
	global $plugins, $mybb;

$upload = array();

	global $plugins, $mybb;

$upload = array();





	if(empty($file['name']) || $file['name'] == "none" || $file['size'] < 1)

	if(empty($file['name']) || $file['name'] == "none" || $file['size'] < 1)

	{

	{

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

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

	}

	}


if(!$filename)
{
$filename = $file['name'];
}


if(!$filename)
{
$filename = $file['name'];
}





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


	$upload['original_filename'] = preg_replace("#/$#", "", $file['name']); // Make the filename safe
$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), '/');

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

	$cdn_path = '';

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








if(!$moved)
{


if(!$moved)
{