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
https://forums.phpfreaks.com/topic/225735-urgent-help/
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
https://forums.phpfreaks.com/topic/225735-urgent-help/#findComment-1165469
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
https://forums.phpfreaks.com/topic/225735-urgent-help/#findComment-1165473
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.