📄 update.php
字号:
<?php
set_time_limit(0);
require_once 'includes/functions_base.inc.php';
require_once 'includes/constants.inc.php';
require_once 'includes/mysql.class.php';
require_once 'includes/configs.inc.php';
require_once 'includes/db.class.php';
if ( !defined ( 'USERS_INDEX' ) )
{
define ( 'USERS_INDEX', 'data/users/index_users.php' ); // LC
define ( 'NAMES_INDEX', 'data/users/index_names.php' ); // default
define ( 'EMAILS_INDEX', 'data/users/index_emails.php' ); // LC
define ( 'APPROVAL_INDEX', 'data/users/index_approval.php' ); // default
define ( 'BANDWIDTH_INDEX', 'data/users/index_bandwidth.php' ); // default
}
class Index extends DB
{
function insert ( $k, $v ) { if ( isset ( $this->_d[$k] ) ) exit ( sprintf ( 'Duplicate key "%s" found.', $k ) ); $this->_d[$k] = $v; }
function search ( $k ) { return isset ( $this->_d[$k] ) ? $this->_d[$k] : false; }
function delete ( $k ) { unset ( $this->_d[$k] ); }
function get_first ( ) { reset ( $this->_d ); $x = each ( $this->_d ); return array ( $x[0] => $x[1] ); }
function get_last ( ) { end ( $this->_d ); $x = each ( $this->_d ); return array ( $x[0] => $x[1] ); }
function get_all ( ) { return $this->_d; }
function get_count ( ) { return count ( $this->_d ); }
function update_value ( $k, $nv ) { if ( isset ( $this->_d[$k] ) ) { $this->_d[$k] = $nv; return true; } return false; }
function update_key ( $k, $nk ) { if ( isset ( $this->_d[$k] ) ) { $v = $this->_d[$k]; unset ( $this->_d[$k] ); $this->_d[$nk] = $v; return true; } return false; }
}
class User extends DB
{
function create($id){return DB::create(USERDATA_DIR.'/user_'.$id.PHP_EXT);}
function open($id){return DB::open(USERDATA_DIR.'/user_'.$id.PHP_EXT);}
function remove($id){return DB::remove(USERDATA_DIR.'/user_'.$id.PHP_EXT);}
function updatebw($v){$this->_d['bw_used']+=$v;}
}
if ( !isset ( $_GET['proceed'] ) )
{
print <<< HTML
<h1>Uploader v6.1 to v6.2 Upgrade</h1>
<p>You are about to update version 6.1 of the uploader to version 6.2. Click proceed ONLY IF you
are running version 6.1.
<br /><br />
Before running this update, you should have:
<ul>
<li>Updated all php files and templates by uploading and overwritting the existing files.</li>
<li>Created a mysql database and edited configs.inc.php to specify the mysql info.</li>
</ul>
<br /><br />
This process may take a while (1 to 5 minutes) depending on how much users you have, so please be patient.
After the upgrade process has completed, delete this file from your server. You will no longer
need the users/data directory. You may delete this if the upgrading process is successful.
<br /><br />
<a href="update.php?proceed">Proceed</a>
</p>
HTML;
exit;
}
$db = new mysqlDB ( $UPL['MYSQL']['host'], $UPL['MYSQL']['username'], $UPL['MYSQL']['password'], $UPL['MYSQL']['database'], $UPL['MYSQL']['persistent'] );
$upl_settings = new DB;
if ( !$upl_settings->open ( UPLOADER_SETTINGS ) ) exit ( 'Could not open upload settings ' . UPLOADER_SETTINGS );
$upl_settings->set ( 'regmsg', 'Registration has been disabled' );
$upl_settings->set ( 'm', 0 );
$upl_settings->set ( 'm_msg', 'The uploader is down for maintenance, we will be back up shortly. Sorry for the inconvenience.' );
$upl_settings->set ( 'uploader_view', 1 );
$upl_settings->save();
print '<br />Uploader settings updated<br />';
$pub_settings = new DB;
if ( !is_file ( PUBLIC_SETTINGS ) )
{
if ( !$pub_settings->create ( PUBLIC_SETTINGS ) ) exit ( 'Could not create public uploader settings file ' . PUBLIC_SETTINGS );
if ( !$pub_settings->open ( PUBLIC_SETTINGS ) ) exit ( 'Could not open public uploader settings file ' . PUBLIC_SETTINGS );
$psettings = array
(
'public_files_dir' => 'public/',
'public_files_url' => 'public/',
'enabled' => 0,
'allowed_filetypes' => 'jpeg,jpg,gif,png',
'max_file_size' => 1024,
'images_only' => 1,
'max_views' => 1000,
'max_bandwidth' => 1024,
'uploader_view' => 1,
'allow_thumbnails' => 1,
'thumb_small' => '100x120',
'thumb_large' => '125x180',
'thumb_border' => 0,
);
$pub_settings->set($psettings,1);
$pub_settings->save();
print '<br />Public Uploader setting file created.<br />';
}
$start = time();
$db->query ( 'DROP TABLE IF EXISTS uploader_users;' );
$str = "
CREATE TABLE uploader_users
(
userid MEDIUMINT UNSIGNED AUTO_INCREMENT,
username VARCHAR(64) NOT NULL,
password VARCHAR(32) NOT NULL,
email VARCHAR(255) NOT NULL,
level TINYINT UNSIGNED DEFAULT '0',
max_messages TINYINT(1) DEFAULT '20',
is_activated TINYINT(1) DEFAULT '0',
is_approved TINYINT(1) DEFAULT '0',
is_suspended TINYINT(1) DEFAULT '0',
last_login_time INT DEFAULT '0',
last_login_ip VARCHAR(15),
reg_email VARCHAR(255) DEFAULT '',
reg_date INT UNSIGNED DEFAULT '0',
reg_ip VARCHAR(15) DEFAULT '0.0.0.0',
pref_accepts_pm TINYINT(1) DEFAULT '1',
pref_show_email TINYINT(1) DEFAULT '0',
bw_used DOUBLE UNSIGNED NOT NULL DEFAULT '0',
bw_max INT UNSIGNED NOT NULL,
bw_reset_last INT UNSIGNED DEFAULT '0',
bw_reset_period TINYINT UNSIGNED DEFAULT '30',
bw_reset_auto TINYINT(1) DEFAULT '1',
bw_xfer_rate SMALLINT UNSIGNED DEFAULT '0',
fl_max_storage SMALLINT UNSIGNED DEFAULT '5',
fl_max_filesize MEDIUMINT UNSIGNED DEFAULT '2048',
fl_allowed_types VARCHAR(255),
fl_images_only TINYINT(1) DEFAULT '1',
fl_rename_permission TINYINT(1) DEFAULT '0',
fl_allow_folders TINYINT(1) DEFAULT '1',
fl_max_folders SMALLINT DEFAULT '10',
fl_watermark TINYINT(1) DEFAULT '1',
fl_has_public TINYINT(1) DEFAULT '0',
xtr_admin_comments VARCHAR(255),
xtr_new_email_address VARCHAR(255),
xtr_activation_code VARCHAR(32),
xtr_password_reset_code VARCHAR(32),
xtr_change_email_code VARCHAR(32),
PRIMARY KEY (userid),
KEY (username),
KEY (fl_has_public)
);";
if ( !$db->query ( $str ) ) exit ( $db->error (__LINE__,__FILE__) );
$db->query ( 'DROP TABLE IF EXISTS uploader_messages;' );
$str = "
CREATE TABLE uploader_messages
(
messageid INT UNSIGNED AUTO_INCREMENT,
userid MEDIUMINT UNSIGNED NOT NULL,
from_id MEDIUMINT UNSIGNED NOT NULL,
from_username VARCHAR(64) NOT NULL,
subject VARCHAR(255) NOT NULL,
message TEXT DEFAULT '',
folder TINYINT NOT NULL,
date INT UNSIGNED NOT NULL,
is_read TINYINT(1) DEFAULT '0',
PRIMARY KEY (messageid),
KEY(userid)
);";
if ( !$db->query ( $str ) ) exit ( $db->error (__LINE__,__FILE__) );
$db->query ( "DROP TABLE IF EXISTS uploader_puploads" );
$str = "
CREATE TABLE uploader_puploads
(
upload_id INT UNSIGNED AUTO_INCREMENT,
upload_name VARCHAR(64) DEFAULT '',
upload_date INT UNSIGNED NOT NULL,
upload_comments VARCHAR(255) DEFAULT '',
upload_key VARCHAR(32) NOT NULL,
upload_ip VARCHAR(16) NOT NULL,
PRIMARY KEY (upload_id)
);";
if ( !$db->query ( $str ) ) exit ( $db->error (__LINE__,__FILE__) );
$db->query ( "DROP TABLE IF EXISTS uploader_pfiles" );
$str = "
CREATE TABLE uploader_pfiles
(
file_id INT UNSIGNED AUTO_INCREMENT,
file_name VARCHAR(128) NOT NULL,
file_rname VARCHAR(128) NOT NULL,
file_size INT UNSIGNED NOT NULL,
file_views INT UNSIGNED DEFAULT 0,
file_isimage TINYINT(1) DEFAULT 0,
file_hasthumb TINYINT(1) DEFAULT 0,
upload_id INT UNSIGNED NOT NULL,
PRIMARY KEY (file_id),
KEY(upload_id)
);";
if ( !$db->query ( $str ) ) exit ( $db->error (__LINE__,__FILE__) );
$users_idx = new Index;
if ( !$users_idx->open ( USERS_INDEX ) ) exit ( 'Could not open index ' . USERS_INDEX );
$all_users = $users_idx->all();
$total_users = count ( $all_users );
$user = new User;
$i = 0;
$converted = 0;
print 'Users: ' . $total_users . '<br />Converting: ';
while ( list ( $name, $userid ) = each ( $all_users ) )
{
$i++;
if ( $user->open ( $userid ) )
{
$userinfo = $user->all();
switch ( $userinfo['fl_allow_rename'] )
{
default:
case 'norename': $rename_perm = 0; break;
case 'nameonly': $rename_perm = 1; break;
case 'all': $rename_perm = 2; break;
}
if ( $i == 100 )
{
print ceil ( ( $converted / $total_users ) * 100 ) . '%, ';
flush();
$i = 0;
}
$insert = array
(
'userid' => $userid,
'username' => $userinfo['name'],
'password' => $userinfo['password'],
'email' => $userinfo['email'],
'level' => $userinfo['level'],
'max_messages' => $userinfo['max_messages'],
'is_activated' => (int)$userinfo['is_activated'],
'is_approved' => (int)$userinfo['is_approved'],
'is_suspended' => (int)$userinfo['is_suspended'],
'last_login_time' => $userinfo['xtr_last_login_time'],
'last_login_ip' => $userinfo['xtr_last_login_ip'],
'reg_email' => $userinfo['reg_email'],
'reg_date' => $userinfo['reg_date'],
'reg_ip' => $userinfo['reg_ip'],
'pref_accepts_pm' => (int)$userinfo['prf_private_msg'],
'pref_show_email' => (int)$userinfo['prf_public_email'],
'bw_used' => $userinfo['bw_used'],
'bw_max' => $userinfo['bw_max'],
'bw_reset_last' => $userinfo['bw_last_reset'],
'bw_reset_period' => $userinfo['bw_reset_period'],
'bw_reset_auto' => $userinfo['bw_auto_reset'],
'bw_xfer_rate' => 0,
'fl_max_storage' => $userinfo['fl_max_storage'],
'fl_max_filesize' => $userinfo['fl_max_filesize'],
'fl_allowed_types' => $userinfo['fl_allowed_filetypes'],
'fl_images_only' => (int)$userinfo['fl_images_only'],
'fl_rename_permission' => $rename_perm,
'fl_allow_folders' => (int)$userinfo['fl_create_folder'],
'fl_max_folders' => $userinfo['fl_max_folders'],
'fl_watermark' => (int)$userinfo['fl_watermark'],
'xtr_admin_comments' => $db->escape($userinfo['xtr_admin_comments']),
'xtr_new_email_address' => $userinfo['xtr_new_email_addr'],
'xtr_activation_code' => $userinfo['xtr_activation_code'],
'xtr_password_reset_code' => $userinfo['xtr_password_code'],
'xtr_change_email_code' => $userinfo['xtr_change_email_code'],
);
$query = 'INSERT INTO uploader_users SET ' . $db->buildInsertStatement ( $insert ) . ';';
if ( !$db->query ( $query ) ) exit ( $db->error ( ) );
$messages = $userinfo['messages'];
if ( count ( $messages ) )
{
while ( list ( $date, $msg ) = each ( $messages ) )
{
$insert = array
(
'messageid' => NULL,
'userid' => $userid,
'from_id' => $msg['id'],
'from_username' => $db->escape($msg['name']),
'subject' => $db->escape($msg['subject']),
'message' => $db->escape($msg['message']),
'folder' => 0,
'date' => $date,
'is_read' => (int)$msg['read'],
);
}
$query = 'INSERT INTO uploader_messages SET ' . $db->buildInsertStatement ( $insert ) . ';';
if ( !$db->query ( $query ) ) exit ( $db->error ( __LINE__, __FILE__ ) );
}
$user->close();
$converted++;
}
}
print '<h1>Update completed in ' . (time()-$start) . 'seconds.</h1>';
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -