Forum Moderators: coopster

Message Too Old, No Replies

Copy Function

         

RogueDogg

1:05 am on Jun 22, 2007 (gmt 0)

10+ Year Member



I have found this function here on WebmasterWorld and other sites, I have made a minor modification to it so that it [u]SHOULD[/u] accept variables from a submitted form however I get this error:

Parse error: syntax error, unexpected $end in /var/www/vhosts/example.com/httpdocs/builder/copy4.php on line 26

FYI Short_open_tags = ON

Could someone please help.

Thanks in advance.


<?
if(isset($_POST['submit'])) {

$source = '/var/www/vhosts/$domain/cgi-bin/$cuid';
$dest = '/var/www/vhosts/$domain/cgi-bin/$cuid';

function copy_dir($source, $destination) {
if (is_file($source)) {
$perm = fileperms($source);
copy($source, $destination);
chmod($destination, $perm);
}
if (is_dir($source)) {
$oldmask = umask(0);
mkdir($destination, 0777);
umask($oldmask);
$dir_handle = opendir($source);
while ($files = readdir($dir_handle)) if( $files!= "." && $files!= "..") $file_array[] = $files;
closedir($dir_handle);
}
for($i=0; $i<count($file_array); $i++) {
$file = $file_array[$i];
if ($destination!= "$source/$file") copy_dir("$source/$file", "$destination/$file");
}
}
?>

[edited by: eelixduppy at 1:37 am (utc) on June 22, 2007]
[edit reason] example.com [/edit]

eelixduppy

1:40 am on Jun 22, 2007 (gmt 0)



>> unexpected $end

This means that you are missing a closing bracket. Add a closing bracket, }, to the end of the script. That is where it looks like it belongs.

RogueDogg

2:01 am on Jun 22, 2007 (gmt 0)

10+ Year Member



Hey buddy, yeah I remembered what you taught me the other night and tried that. Now what happens is the script doesn't pop any errors but it doesn't do anything either so... not sure what's going on here. Let me know what you think...Do you think I need to post my form code here too?

Thanks

**Also make note that $dest = $destination and I have fixed that in my script and added the } at the end of the file, again doesn't pop an error but doesn't do what the script is suppose to do.

[edited by: RogueDogg at 2:06 am (utc) on June 22, 2007]

jatar_k

12:37 pm on Jun 22, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



could just be a permission issue but try to handle the return from you copy statement

instead of
copy($source, $destination);

use

if (!copy($source, $destination)) {
echo 'could not copy: ',$source,' to: '$destination;
}

this way you can see if that is actually what is failing and then check you paths as well

RogueDogg

6:59 pm on Jun 22, 2007 (gmt 0)

10+ Year Member



K I made the changes you suggested. I had to make a minor modification but here is what I ended up with in the script:

if (!copy($source, $destination)) {
//[i]What you suggested I put[/i]
//echo 'could not copy: ',$source ' to: ',$destination;
//[i]What I ended up using[/i]
echo 'could not copy: ' . $source . ' to: ' . $destination;
}

The script runs with no errors but again does not actually work. I'm at a loss, I've had alot of interaction with people and they seem to be at a loss as well... If anyone can help I'd be greatly appreciative.

Thanks in advance....

RogueDogg

10:39 pm on Jun 22, 2007 (gmt 0)

10+ Year Member



ok so I think I've made some progess, here is the most current code and errors:


<?
if(isset($_POST['Submit'])) {

$source = '/var/www/vhosts/example.com/cgi-bin/$cuid';
$destination = '/var/www/vhosts/$domain/cgi-bin/$cuid';

copy_dir();

}else{ echo "script failed";
exit;
}

function copy_dir($source, $destination) {
if (is_file($source)) {
//echo $source;
$perm = fileperms($source);
//copy($source, $destination);
if (!copy($source, $destination)) {
echo 'could not copy: ' . $source . ' to: ' . $destination;
}
chmod($destination, $perm);
}
if (is_dir($source)) {
$oldmask = umask(0);
mkdir($destination, 0777);
umask($oldmask);
$dir_handle = opendir($source);
while ($files = readdir($dir_handle)) if( $files!= "." && $files!= "..") $file_array[] = $files;
closedir($dir_handle);
}
for($i=0; $i<count($file_array); $i++) {
$file = $file_array[$i];
if ($destination!= "$source/$file") copy_dir("$source/$file", "$destination/$file");
}
}

?>

K here are the errors:

Warning: Missing argument 1 for copy_dir(), called in /var/www/vhosts/example.com/httpdocs/builder/copy4.php on line 7 and defined in /var/www/vhosts/example.com/httpdocs/builder/copy4.php on line 13

Warning: Missing argument 2 for copy_dir(), called in /var/www/vhosts/example.com/httpdocs/builder/copy4.php on line 7 and defined in /var/www/vhosts/example.com/httpdocs/builder/copy4.php on line 13

Notice: Undefined variable: source in /var/www/vhosts/example.com/httpdocs/builder/copy4.php on line 14

Notice: Undefined variable: source in /var/www/vhosts/example.com/httpdocs/builder/copy4.php on line 24

Notice: Undefined variable: file_array in /var/www/vhosts/example.com/httpdocs/builder/copy4.php on line 32

jatar_k

1:07 am on Jun 23, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you have call to copy_dir(); near the top of your script which doesn't have any params, it also occurs before the function is defined

try commenting that one, unless you need it there for some reason