grilo Posted January 26, 2011 Share Posted January 26, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/225735-urgent-help/ Share on other sites More sharing options...
grilo Posted January 26, 2011 Author Share Posted January 26, 2011 Anyone? Please? Quote Link to comment https://forums.phpfreaks.com/topic/225735-urgent-help/#findComment-1165467 Share on other sites More sharing options...
litebearer Posted January 26, 2011 Share Posted January 26, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/225735-urgent-help/#findComment-1165469 Share on other sites More sharing options...
grilo Posted January 26, 2011 Author Share Posted January 26, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/225735-urgent-help/#findComment-1165473 Share on other sites More sharing options...
Maq Posted January 26, 2011 Share Posted January 26, 2011 1) Refrain from titling your threads URGENT, this is under the forum guidelines (Forum Guidelines #2). 2) DO NOT bump posts after 25 minutes. Give adequate time for users to read and answer your post. Quote Link to comment https://forums.phpfreaks.com/topic/225735-urgent-help/#findComment-1165475 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.