diff options
author | Meik Sievertsen <acydburn@phpbb.com> | 2005-03-21 23:10:11 +0000 |
---|---|---|
committer | Meik Sievertsen <acydburn@phpbb.com> | 2005-03-21 23:10:11 +0000 |
commit | e4fe2d853d3e96ec4d6493e1651d93ab1b73ae1c (patch) | |
tree | 8b687905d08d6af99c3396fa5c0470c7bbef4ccb /phpBB/includes/functions_user.php | |
parent | a4e51c9699c7a09bea32ad832a9818abba008801 (diff) | |
download | forums-e4fe2d853d3e96ec4d6493e1651d93ab1b73ae1c.tar forums-e4fe2d853d3e96ec4d6493e1651d93ab1b73ae1c.tar.gz forums-e4fe2d853d3e96ec4d6493e1651d93ab1b73ae1c.tar.bz2 forums-e4fe2d853d3e96ec4d6493e1651d93ab1b73ae1c.tar.xz forums-e4fe2d853d3e96ec4d6493e1651d93ab1b73ae1c.zip |
- and my second attempt
git-svn-id: file:///svn/phpbb/trunk@5109 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/functions_user.php')
-rw-r--r-- | phpBB/includes/functions_user.php | 127 |
1 files changed, 16 insertions, 111 deletions
diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 076d617e6b..1a49b0a5a3 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -187,6 +187,7 @@ function user_delete($mode, $user_id) { $sql = 'SELECT user_id, username FROM ' . USERS_TABLE . ' + WHERE user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ') ORDER BY user_id DESC LIMIT 1'; $result = $db->sql_query($sql); @@ -262,6 +263,7 @@ function user_active_flip($user_id, $user_type, $user_actkey = false, $username { $sql_ary['user_actkey'] = $user_actkey; } + $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE user_id = $user_id"; $db->sql_query($sql); @@ -932,126 +934,29 @@ function avatar_upload($data, &$error) { global $phpbb_root_path, $config, $db, $user; + // Init upload class + include_once($phpbb_root_path . 'includes/functions_upload.php'); + $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $config['avatar_filesize'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height']); + if (!empty($_FILES['uploadfile']['name'])) { - $filename = $_FILES['uploadfile']['tmp_name']; - $filesize = $_FILES['uploadfile']['size']; - $realname = $_FILES['uploadfile']['name']; - - // Filesize is too big or it's 0 if it was larger than the maxsize in the upload form - if ($filesize > $config['avatar_filesize'] || $filesize == 0) - { - $error[] = sprintf($user->lang['AVATAR_WRONG_FILESIZE'], $config['avatar_filesize']); - return false; - } - - if (file_exists($filename) && preg_match('#^(.*?)\.(jpg|jpeg|gif|png)$#i', $realname, $match)) - { - $realname = $match[1]; - $filetype = $match[2]; - $php_move = 'move_uploaded_file'; - } - else - { - $error[] = $user->lang['AVATAR_NOT_UPLOADED']; - return false; - } - } - else if (preg_match('#^(http://).*?\.(jpg|jpeg|gif|png)$#i', $data['uploadurl'], $match)) - { - if (empty($match[2])) - { - $error[] = $user->lang['AVATAR_URL_INVALID']; - return false; - } - - $url = parse_url($data['uploadurl']); - - $host = $url['host']; - $path = dirname($url['path']); - $port = (!empty($url['port'])) ? $url['port'] : 80; - $filetype = array_pop(explode('.', $url['path'])); - $realname = basename($url['path'], '.' . $filetype); - $filename = $url['path']; - $filesize = 0; - - if (!($fsock = @fsockopen($host, $port, $errno, $errstr))) - { - $error[] = $user->lang['AVATAR_NOT_UPLOADED']; - return false; - } - - fputs($fsock, 'GET /' . $filename . " HTTP/1.1\r\n"); - fputs($fsock, "HOST: " . $host . "\r\n"); - fputs($fsock, "Connection: close\r\n\r\n"); - - $avatar_data = ''; - while (!feof($fsock)) - { - $avatar_data .= fread($fsock, $config['avatar_filesize']); - } - @fclose($fsock); - $avatar_data = array_pop(explode("\r\n\r\n", $avatar_data)); - - if (empty($avatar_data)) - { -// TODO: The above code to fetch images doesn't work with quite a few servers. This part needs some changes.. - $error[] = $user->lang['AVATAR_NOT_UPLOADED'] . '<br />Please try uploading the file manually.'; - return false; - } - unset($url_ary); - - $tmp_path = (!@ini_get('safe_mode')) ? false : $phpbb_root_path . 'cache'; - $filename = tempnam($tmp_path, uniqid(rand()) . '-'); - - if (!($fp = @fopen($filename, 'wb'))) - { - $error[] = $user->lang['AVATAR_NOT_UPLOADED']; - return false; - } - $filesize = fwrite($fp, $avatar_data); - fclose($fp); - unset($avatar_data); - - if (!$filesize) - { - unlink($filename); - $error[] = $user->lang['AVATAR_NOT_UPLOADED']; - return false; - } - - $php_move = 'copy'; + $file = $upload->form_upload('uploadfile'); } - - list($width, $height) = getimagesize($filename); - - if ($width > $config['avatar_max_width'] || $height > $config['avatar_max_height'] || $width < $config['avatar_min_width'] || $height < $config['avatar_min_height'] || !$width || !$height) + else { - return sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height']); + $file = $upload->remote_upload($data['uploadurl']); } - // Replace any chars which may cause us problems with _ - $bad_chars = array(' ', '/', ':', '*', '?', '"', '<', '>', '|'); - - $realfilename = $data['user_id'] . '_' . str_replace($bad_chars, '_', $realname) . '.' . $filetype; + $file->clean_filename('real', $user->data['user_id'] . '_'); + $file->move_file($config['avatar_path']); - if (!$php_move($filename, $phpbb_root_path . $config['avatar_path'] . '/' . $realfilename)) + if (sizeof($file->error)) { - @unlink($filename); - $error[] = $user->lang['AVATAR_NOT_UPLOADED']; - return false; + $file->remove(); + $error = array_merge($error, $file->error); } - @unlink($filename); - - $filesize = @filesize($phpbb_root_path . $config['avatar_path'] . "/$realfilename"); - if (!$filesize || $filesize > $config['avatar_filesize']) - { - @unlink($phpbb_root_path . $config['avatar_path'] . "/$realfilename"); - $error[] = sprintf($user->lang['AVATAR_WRONG_FILESIZE'], $config['avatar_filesize']); - return false; - } - - return array(AVATAR_UPLOAD, $realfilename, $width, $height); + + return array(AVATAR_UPLOAD, $file->get('realname'), $file->get('width'), $file->get('height')); } function avatar_gallery($category, &$error) |