Jump to content

URGENT HELP!!!


grilo

Recommended Posts

Please can anyone assist me on this matter and tell me what am i doing wrong?

 

I need to copy directory contents from "admin" folder to new created one.

<?php
$newdirname = $_POST['Username'];

if(file_exists($newdirname))
{
print "&error_=Restaurante já existente.&";

}else{

$old = umask(0);
mkdir($newdirname,0777);
umask($old); 


echo"&error_=Obrigado - Restaurante adicionado com sucesso&";

$source = 'admin';
$destination = $newdirname."/".$source;
copy($source, $destination);

function copy_directory( $source, $destination ) {
if ( is_dir( $source ) ) {
	@mkdir( $destination );
	$directory = dir( $source );
	while ( FALSE !== ( $readdirectory = $directory->read() ) ) {
		if ( $readdirectory == '.' || $readdirectory == '..' ) {
			continue;
		}
		$PathDir = $source . '/' . $readdirectory; 
		if ( is_dir( $PathDir ) ) {
			copy_directory( $PathDir, $destination . '/' . $readdirectory );
			continue;
		}
		copy( $PathDir, $destination . '/' . $readdirectory );
	}

	$directory->close();
}else {
	copy( $source, $destination );
}
}
}

?> 

 

I need urgent help!

Thanks

Link to comment
Share on other sites

perhaps this may help...

Here's a simple recursive function to copy entire directories

 

Note to do your own check to make sure the directory exists that you first call it on.

 

<?php

function recurse_copy($src,$dst) {

    $dir = opendir($src);

    @mkdir($dst);

    while(false !== ( $file = readdir($dir)) ) {

        if (( $file != '.' ) && ( $file != '..' )) {

            if ( is_dir($src . '/' . $file) ) {

                recurse_copy($src . '/' . $file,$dst . '/' . $file);

            }

            else {

                copy($src . '/' . $file,$dst . '/' . $file);

            }

        }

    }

    closedir($dir);

}

?>

source: http://php.net/manual/en/function.copy.php

Link to comment
Share on other sites

Hey litebearer...

Thanks for the quick reply.... ;)

 

I already tried almost every solution i found on web, but the problem is residing on copying files from admin folder in server to new dir created by user, i tried to add this two separate actions 1. create new dir $newdirname input by user and 2. copy files from admin to new dir.

 

First - success in creating new dir by user input

Second - failure in copying files.

 

$source = 'admin';
$destination = $newdirname."/".$source;
copy($source, $destination);

 

and then the copy function....

 

Al the files are chmod 0777, but still no progress...

 

Can you help?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.