rincewind666
asked on
Error Fatal error: [] operator not supported for strings in /home/a2zinte/public_html/online/includes/functions.php on line 103 (500 points)
I have moved to a new server and my script is no longer working. It worked OK on my old server.
I am getting the following error when I try to load "copy.php":
Fatal error: [] operator not supported for strings in /home/a2zinte/public_html/ online/inc ludes/func tions.php on line 103
I have included the code for "copy.php" and "functions.php".
I am giving the maximum 500 points as this is urgent, together with my grateful thanks.
I am getting the following error when I try to load "copy.php":
Fatal error: [] operator not supported for strings in /home/a2zinte/public_html/
I have included the code for "copy.php" and "functions.php".
I am giving the maximum 500 points as this is urgent, together with my grateful thanks.
COPY.PHP: (functions.php also given below)
==========
<?
include_once('includes/application.php');
include_once('includes/auth.php');
//get user directory
$directory = get_user_directory();
if ( isset($_POST['create_directory']) && $_POST['create_directory'] == 'create_directory' ) {
if (!is_local()) {
//ftp data save to session
if ( isset($_POST['ftp_server']) && $_POST['ftp_server'] != '' && isset($_POST['ftp_directory']) && $_POST['ftp_directory'] != '' && isset($_POST['ftp_username']) && $_POST['ftp_username'] != '' && isset($_POST['ftp_password']) && $_POST['ftp_password'] != '' ) {
$_SESSION['ftp_server'] = $_POST['ftp_server'];
$_SESSION['ftp_directory'] = $_POST['ftp_directory'];
$_SESSION['ftp_username'] = $_POST['ftp_username'];
$_SESSION['ftp_password'] = $_POST['ftp_password'];
//save information about ftp server to database
$sql = '
update users set
ftp_server = \''.addslashes($_POST['ftp_server']).'\',
ftp_directory = \''.addslashes($_POST['ftp_directory']).'\',
ftp_username = \''.addslashes($_POST['ftp_username']).'\',
ftp_password = \''.addslashes($_POST['ftp_password']).'\'
where username = \''.addslashes($_SESSION['username']).'\'
';
mysql_query($sql);
if ($error_message = mysql_error()) { put_error($error_message); }
}else{
put_error('Please input FTP data' );
}
}
if (!is_error()) {
//copy directory from source to destination
if (!dircopy($cfg['source'], $directory, false)) {
put_error('Can\'t copy directory \'' . $cfg['source'] . '\' to \'' . $directory . '\'' );
}else{
put_error('Copied \'' . $cfg['source'] . '\' to \'' . $directory . '\'' );
if (is_local()) {
header('Location: edit.php');
die;
}else {
if ($cfg['copy_ftp_php']) {
//copy 'php' directory to destination ftp server
dircopy_to_ftp('php', $_SESSION['ftp_directory'] . '/php/', $_SESSION['ftp_server'], $_SESSION['ftp_username'], $_SESSION['ftp_password'], false);
header('Location: copy_ftp.php');
die;
}else {
if ($cfg['cpanel_mysql_db_create_tool']) {
header('Location: create_database_choise.php');
die;
}
header('Location: edit.php');
die;
}
}
}
}
}
//get information about ftp server from database
$sql = '
select
ftp_server,
ftp_directory,
ftp_username,
ftp_password
from users
where username = \''.addslashes($_SESSION['username']).'\'
';
$r = mysql_query($sql);
if ($error_message = mysql_error()) { put_error($error_message); }
if ($row = mysql_fetch_assoc($r)) {
$ftp_server = $row['ftp_server'];
$ftp_directory = $row['ftp_directory'];
$ftp_username = $row['ftp_username'];
$ftp_password = $row['ftp_password'];
}
include('../../header/header.htm');
include('header.php');
include('../../messages/copy.htm');
?>
<form action="" method="post" onsubmit="return popHiddenLayer();">
<table cellpadding=0 cellspacing=0 id="main_table">
<tr>
<td>
From directory:
</td>
<td>
<? echo $cfg['source']; ?>
</td>
</tr>
<?
if (!is_local()) {?>
<tr>
<td>
FTP server host:
</td>
<td>
<input name="ftp_server" type="text" value="<? echo $ftp_server; ?>">
</td>
</tr>
<tr>
<td>
FTP username:
</td>
<td>
<input name="ftp_username" type="text" value="<? echo $ftp_username; ?>">
</td>
</tr>
<tr>
<td>
FTP password:
</td>
<td>
<input name="ftp_password" type="password" value="<? echo $ftp_password; ?>">
</td>
</tr>
<tr>
<td>
FTP directory:
</td>
<td>
<?/* <input name="ftp_directory" type="text" value="<? echo (($ftp_directory=='')?$cfg['default_ftp_dir_prefix'] . $directory:$ftp_directory); ?>">*/?>
<input name="ftp_directory" type="text" value="<? echo $cfg['default_ftp_dir_prefix'] . $directory; ?>">
</td>
</tr>
<? } else {
?>
<tr>
<td>
To directory:
</td>
<td>
<? echo $directory; ?>
</td>
</tr>
<?
}
?>
<tr>
<td>
</td>
<td>
<input type="hidden" name="create_directory" value="create_directory">
<input type="submit" value="Next">
</td>
</tr>
</table>
</form>
<?
include('../../logo.htm');
include('footer.php');
include('../../banner.htm');
include('../../header/footer.htm');
?>
FUNCTIONS.PHP
=============
<?
/* Copies a dir to another. Optionally caching the dir/file structure, used to synchronize similar destination dir (web farm).
*
* @param $src_dir str Source directory to copy.
* @param $dst_dir str Destination directory to copy to.
* @param $verbose bool Show or hide file copied messages
* @param $use_cached_dir_trees bool Set to true to cache src/dst dir/file structure. Used to sync to web farms
* (avoids loading the same dir tree in web farms; making sync much faster).
* @return Number of files copied/updated.
* @example
* To copy a dir:
* dircopy("c:\max\pics", "d:\backups\max\pics");
*
* To sync to web farms (webfarm 2 to 4 must have same dir/file structure (run once with cache off to make sure if necessary)):
* dircopy("//webfarm1/wwwroot", "//webfarm2/wwwroot", false, true);
* dircopy("//webfarm1/wwwroot", "//webfarm3/wwwroot", false, true);
* dircopy("//webfarm1/wwwroot", "//webfarm4/wwwroot", false, true);
*/
function dircopy($src_dir, $dst_dir, $verbose = false, $use_cached_dir_trees = false)
{
static $cached_src_dir;
static $src_tree;
static $dst_tree;
$num = 0;
if (($slash = substr($src_dir, -1)) == "\\" || $slash == "/") $src_dir = substr($src_dir, 0, strlen($src_dir) - 1);
if (($slash = substr($dst_dir, -1)) == "\\" || $slash == "/") $dst_dir = substr($dst_dir, 0, strlen($dst_dir) - 1);
if (!$use_cached_dir_trees || !isset($src_tree) || $cached_src_dir != $src_dir)
{
$src_tree = get_dir_tree($src_dir);
$cached_src_dir = $src_dir;
$src_changed = true;
}
if (!$use_cached_dir_trees || !isset($dst_tree) || $src_changed)
$dst_tree = get_dir_tree($dst_dir);
if (!is_dir($dst_dir)) mkdir($dst_dir, 0777);
foreach ($src_tree as $file => $src_mtime)
{
if (!isset($dst_tree[$file]) && $src_mtime === false) // dir
mkdir("$dst_dir/$file");
elseif (!isset($dst_tree[$file]) && $src_mtime || isset($dst_tree[$file]) && $src_mtime > $dst_tree[$file]) // file
{
if (copy("$src_dir/$file", "$dst_dir/$file"))
{
if($verbose) echo "Copied '$src_dir/$file' to '$dst_dir/$file'<br>\r\n";
touch("$dst_dir/$file", $src_mtime);
$num++;
} else
echo "<font color='red'>File '$src_dir/$file' could not be copied!</font><br>\r\n";
}
}
return $num;
}
/* Creates a directory / file tree of a given root directory
*
* @param $dir str Directory or file without ending slash
* @param $root bool Must be set to true on initial call to create new tree.
* @return Directory & file in an associative array with file modified time as value.
*/
function get_dir_tree($dir, $root = true)
{
static $tree;
static $base_dir_length;
if ($root)
{
$tree = array();
$base_dir_length = strlen($dir) + 1;
}
if (is_file($dir))
{
//if (substr($dir, -8) != "/CVS/Tag" && substr($dir, -9) != "/CVS/Root" && substr($dir, -12) != "/CVS/Entries")
$tree[substr($dir, $base_dir_length)] = filemtime($dir);
} elseif (is_dir($dir) && $di = dir($dir)) // add after is_dir condition to ignore CVS folders: && substr($dir, -4) != "/CVS"
{
if (!$root) $tree[substr($dir, $base_dir_length)] = false;
while (($file = $di->read()) !== false)
if ($file != "." && $file != "..")
get_dir_tree("$dir/$file", false);
$di->close();
}
if ($root)
return $tree;
}
function show_errors() { if ( isset($_SESSION['error_message']) && is_array($_SESSION['error_message']) && sizeof($_SESSION['error_message']) > 0 ) { for ($i = 0,$n = sizeof($_SESSION['error_message']); $i < $n; $i++) { echo '<span class="error">' . $_SESSION['error_message'][$i] . '</span><br />'."\n";
}
unset($_SESSION['error_message']); } }
function is_error() {
if ( isset($_SESSION['error_message']) && is_array($_SESSION['error_message']) && sizeof($_SESSION['error_message']) > 0 ) { return true;
}else { return false; }
}
function put_error($error_message) {
$_SESSION['error_message'][] = $error_message;
}
function is_user_login() {
if ( isset($_SESSION['username']) && $_SESSION['username'] != '' ) {
return true;
}else {
return false;
}
}
function get_file_perms($filename) {
$perms = fileperms($filename);
if (($perms & 0xC000) == 0xC000) {
// Socket
$info = 's';
} elseif (($perms & 0xA000) == 0xA000) {
// Symbolic Link
$info = 'l';
} elseif (($perms & 0x8000) == 0x8000) {
// Regular
$info = '-';
} elseif (($perms & 0x6000) == 0x6000) {
// Block special
$info = 'b';
} elseif (($perms & 0x4000) == 0x4000) {
// Directory
$info = 'd';
} elseif (($perms & 0x2000) == 0x2000) {
// Character special
$info = 'c';
} elseif (($perms & 0x1000) == 0x1000) {
// FIFO pipe
$info = 'p';
} else {
// Unknown
$info = 'u';
}
// Owner
$info .= (($perms & 0x0100) ? 'r' : '-');
$info .= (($perms & 0x0080) ? 'w' : '-');
$info .= (($perms & 0x0040) ?
(($perms & 0x0800) ? 's' : 'x' ) :
(($perms & 0x0800) ? 'S' : '-'));
// Group
$info .= (($perms & 0x0020) ? 'r' : '-');
$info .= (($perms & 0x0010) ? 'w' : '-');
$info .= (($perms & 0x0008) ?
(($perms & 0x0400) ? 's' : 'x' ) :
(($perms & 0x0400) ? 'S' : '-'));
// World
$info .= (($perms & 0x0004) ? 'r' : '-');
$info .= (($perms & 0x0002) ? 'w' : '-');
$info .= (($perms & 0x0001) ?
(($perms & 0x0200) ? 't' : 'x' ) :
(($perms & 0x0200) ? 'T' : '-'));
return $info;
}
//get user directory
function get_user_directory() {
$sql = '
select dir
from users
where username = \''.addslashes($_SESSION['username']).'\'
';
$r = mysql_query($sql);
$n = mysql_num_rows($r);
return mysql_result($r,0,'dir');
}
function dircopy_to_ftp($local_dir, $remote_dir, $server, $username, $password,$verbose = false) {
if (ob_get_level() == 0 && $verbose) ob_start();
if (($slash = substr($local_dir, -1)) != "/" ) $local_dir .= '/';
if (($slash = substr($remote_dir, -1)) != "/" ) $remote_dir .= '/';
$conn_id = ftp_connect($server);
if ($conn_id) {
ftp_login ($conn_id, $username, $password);
ftp_uploaddirectory($conn_id, $local_dir, $remote_dir);
ftp_chmod_remote($conn_id);
ftp_quit($conn_id);
exec('rm -rf ' . $local_dir);
}
if ($verbose) ob_end_flush();
}
function ftp_uploaddirectory($conn_id, $local_dir, $remote_dir) {
ftp_chdir($conn_id, "/");
@ftp_mkdir($conn_id, $remote_dir);
if ($verbose) echo "mkdir $remote_dir" . "<br>\n";
$handle = opendir($local_dir);
while (($file = readdir($handle)) !== false)
{
if (($file != '.') && ($file != '..'))
{
if (is_dir($local_dir.$file))
{
ftp_uploaddirectory($conn_id, $local_dir.$file.'/', $remote_dir.$file.'/');
}
else
$f[] = $file;
}
}
closedir($handle);
if (count($f))
{
sort($f);
ftp_chdir($conn_id, "/");
ftp_chdir($conn_id, $remote_dir);
if ($verbose) echo "cd $remote_dir" . "<br>\n";
foreach ($f as $files)
{
if ($verbose) ob_flush();
if ($verbose) flush();
if ($verbose) echo $local_dir.$files;
if ($verbose) ob_flush();
if ($verbose) flush();
$from = fopen("$local_dir$files", 'r');
if ($from) {
$upload = ftp_fput($conn_id, $files, $from, FTP_BINARY);
}else{
$upload = false;
}
if ($verbose) {
echo " - ";
if ($upload) {
echo " <font color=\"green\">OK</font> ";
}else{
echo " <font color=\"red\">Error</font> ";
}
echo "<br>\n";
ob_flush();
flush();
}
}
}
}
//chmod remote files
function ftp_chmod_remote($conn_id) {
ftp_chdir($conn_id, "/");
foreach ($_SESSION['chmod_selected_files'] as $file_name => $file_chmod) {
if ($file_chmod != '') {
//get full filename
$file = $_SESSION['ftp_directory'] . '/' . $file_name;
if (function_exists('ftp_chmod')) {
if (ftp_chmod($conn_id, octdec('0'.$file_chmod), $file)) {
put_error('Chmoded file \'' . $file . '\' to \'' . $file_chmod . '\'');
}else{
put_error('Can\'t chmod file \'' . $file . '\' to \'' . $file_chmod . '\'');
}
}
else {
if (ftp_site($conn_id, 'CHMOD 0' . $file_chmod . ' ' . $file)) {
put_error('Chmoded file \'' . $file . '\' to \'' . $file_chmod . '\'');
}
else {
put_error('Can\'t chmod file \'' . $file . '\' to \'' . $file_chmod . '\'');
}
}
}
}
}
//Check copy type
function is_local() { return $_SESSION['copy_type'] == 'local' ? true : false; }
?>
can you show me what is line 103?
ASKER
Line 103:
$_SESSION['error_message'] [] = $error_message;
I give below the the first 103 lines to make it easier (I hope):
<?
/* Copies a dir to another. Optionally caching the dir/file structure, used to synchronize similar destination dir (web farm).
*
* @param $src_dir str Source directory to copy.
* @param $dst_dir str Destination directory to copy to.
* @param $verbose bool Show or hide file copied messages
* @param $use_cached_dir_trees bool Set to true to cache src/dst dir/file structure. Used to sync to web farms
* (avoids loading the same dir tree in web farms; making sync much faster).
* @return Number of files copied/updated.
* @example
* To copy a dir:
* dircopy("c:\max\pics", "d:\backups\max\pics");
*
* To sync to web farms (webfarm 2 to 4 must have same dir/file structure (run once with cache off to make sure if necessary)):
* dircopy("//webfarm1/wwwroo t", "//webfarm2/wwwroot", false, true);
* dircopy("//webfarm1/wwwroo t", "//webfarm3/wwwroot", false, true);
* dircopy("//webfarm1/wwwroo t", "//webfarm4/wwwroot", false, true);
*/
function dircopy($src_dir, $dst_dir, $verbose = false, $use_cached_dir_trees = false)
{
static $cached_src_dir;
static $src_tree;
static $dst_tree;
$num = 0;
if (($slash = substr($src_dir, -1)) == "\\" || $slash == "/") $src_dir = substr($src_dir, 0, strlen($src_dir) - 1);
if (($slash = substr($dst_dir, -1)) == "\\" || $slash == "/") $dst_dir = substr($dst_dir, 0, strlen($dst_dir) - 1);
if (!$use_cached_dir_trees || !isset($src_tree) || $cached_src_dir != $src_dir)
{
$src_tree = get_dir_tree($src_dir);
$cached_src_dir = $src_dir;
$src_changed = true;
}
if (!$use_cached_dir_trees || !isset($dst_tree) || $src_changed)
$dst_tree = get_dir_tree($dst_dir);
if (!is_dir($dst_dir)) mkdir($dst_dir, 0777);
foreach ($src_tree as $file => $src_mtime)
{
if (!isset($dst_tree[$file]) && $src_mtime === false) // dir
mkdir("$dst_dir/$file");
elseif (!isset($dst_tree[$file]) && $src_mtime || isset($dst_tree[$file]) && $src_mtime > $dst_tree[$file]) // file
{
if (copy("$src_dir/$file", "$dst_dir/$file"))
{
if($verbose) echo "Copied '$src_dir/$file' to '$dst_dir/$file'<br>\r\n";
touch("$dst_dir/$file", $src_mtime);
$num++;
} else
echo "<font color='red'>File '$src_dir/$file' could not be copied!</font><br>\r\n";
}
}
return $num;
}
/* Creates a directory / file tree of a given root directory
*
* @param $dir str Directory or file without ending slash
* @param $root bool Must be set to true on initial call to create new tree.
* @return Directory & file in an associative array with file modified time as value.
*/
function get_dir_tree($dir, $root = true)
{
static $tree;
static $base_dir_length;
if ($root)
{
$tree = array();
$base_dir_length = strlen($dir) + 1;
}
if (is_file($dir))
{
//if (substr($dir, -8) != "/CVS/Tag" && substr($dir, -9) != "/CVS/Root" && substr($dir, -12) != "/CVS/Entries")
$tree[substr($dir, $base_dir_length)] = filemtime($dir);
} elseif (is_dir($dir) && $di = dir($dir)) // add after is_dir condition to ignore CVS folders: && substr($dir, -4) != "/CVS"
{
if (!$root) $tree[substr($dir, $base_dir_length)] = false;
while (($file = $di->read()) !== false)
if ($file != "." && $file != "..")
get_dir_tree("$dir/$file", false);
$di->close();
}
if ($root)
return $tree;
}
function show_errors() { if ( isset($_SESSION['error_mes sage']) && is_array($_SESSION['error_ message']) && sizeof($_SESSION['error_me ssage']) > 0 ) { for ($i = 0,$n = sizeof($_SESSION['error_me ssage']); $i < $n; $i++) { echo '<span class="error">' . $_SESSION['error_message'] [$i] . '</span><br />'."\n";
}
unset($_SESSION['error_mes sage']); } }
function is_error() {
if ( isset($_SESSION['error_mes sage']) && is_array($_SESSION['error_ message']) && sizeof($_SESSION['error_me ssage']) > 0 ) { return true;
}else { return false; }
}
function put_error($error_message) {
$_SESSION['error_message'] [] = $error_message;
$_SESSION['error_message']
I give below the the first 103 lines to make it easier (I hope):
<?
/* Copies a dir to another. Optionally caching the dir/file structure, used to synchronize similar destination dir (web farm).
*
* @param $src_dir str Source directory to copy.
* @param $dst_dir str Destination directory to copy to.
* @param $verbose bool Show or hide file copied messages
* @param $use_cached_dir_trees bool Set to true to cache src/dst dir/file structure. Used to sync to web farms
* (avoids loading the same dir tree in web farms; making sync much faster).
* @return Number of files copied/updated.
* @example
* To copy a dir:
* dircopy("c:\max\pics", "d:\backups\max\pics");
*
* To sync to web farms (webfarm 2 to 4 must have same dir/file structure (run once with cache off to make sure if necessary)):
* dircopy("//webfarm1/wwwroo
* dircopy("//webfarm1/wwwroo
* dircopy("//webfarm1/wwwroo
*/
function dircopy($src_dir, $dst_dir, $verbose = false, $use_cached_dir_trees = false)
{
static $cached_src_dir;
static $src_tree;
static $dst_tree;
$num = 0;
if (($slash = substr($src_dir, -1)) == "\\" || $slash == "/") $src_dir = substr($src_dir, 0, strlen($src_dir) - 1);
if (($slash = substr($dst_dir, -1)) == "\\" || $slash == "/") $dst_dir = substr($dst_dir, 0, strlen($dst_dir) - 1);
if (!$use_cached_dir_trees || !isset($src_tree) || $cached_src_dir != $src_dir)
{
$src_tree = get_dir_tree($src_dir);
$cached_src_dir = $src_dir;
$src_changed = true;
}
if (!$use_cached_dir_trees || !isset($dst_tree) || $src_changed)
$dst_tree = get_dir_tree($dst_dir);
if (!is_dir($dst_dir)) mkdir($dst_dir, 0777);
foreach ($src_tree as $file => $src_mtime)
{
if (!isset($dst_tree[$file]) && $src_mtime === false) // dir
mkdir("$dst_dir/$file");
elseif (!isset($dst_tree[$file]) && $src_mtime || isset($dst_tree[$file]) && $src_mtime > $dst_tree[$file]) // file
{
if (copy("$src_dir/$file", "$dst_dir/$file"))
{
if($verbose) echo "Copied '$src_dir/$file' to '$dst_dir/$file'<br>\r\n";
touch("$dst_dir/$file", $src_mtime);
$num++;
} else
echo "<font color='red'>File '$src_dir/$file' could not be copied!</font><br>\r\n";
}
}
return $num;
}
/* Creates a directory / file tree of a given root directory
*
* @param $dir str Directory or file without ending slash
* @param $root bool Must be set to true on initial call to create new tree.
* @return Directory & file in an associative array with file modified time as value.
*/
function get_dir_tree($dir, $root = true)
{
static $tree;
static $base_dir_length;
if ($root)
{
$tree = array();
$base_dir_length = strlen($dir) + 1;
}
if (is_file($dir))
{
//if (substr($dir, -8) != "/CVS/Tag" && substr($dir, -9) != "/CVS/Root" && substr($dir, -12) != "/CVS/Entries")
$tree[substr($dir, $base_dir_length)] = filemtime($dir);
} elseif (is_dir($dir) && $di = dir($dir)) // add after is_dir condition to ignore CVS folders: && substr($dir, -4) != "/CVS"
{
if (!$root) $tree[substr($dir, $base_dir_length)] = false;
while (($file = $di->read()) !== false)
if ($file != "." && $file != "..")
get_dir_tree("$dir/$file",
$di->close();
}
if ($root)
return $tree;
}
function show_errors() { if ( isset($_SESSION['error_mes
}
unset($_SESSION['error_mes
function is_error() {
if ( isset($_SESSION['error_mes
}else { return false; }
}
function put_error($error_message) {
$_SESSION['error_message']
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many thanks nplib. Your help is greatly appreciated.