jaymc Posted April 23, 2008 Share Posted April 23, 2008 Im trying to copy the entire contents of 1 folder to another, im using shell commands via php system or exec command, its not working though system("cp -ap $dir_to_read/$file/. $dir_to_read"); exec("cp -ap $dir_to_read/$file/. $dir_to_read"); That returns cp -ap 'BaseFolder/folder/.' 'BaseFolder' and if I copy and paste that straight into ssh it works fine, so its not the syntax or the variables All the folders in question are 777 etc etc, I have rights to use system command as its my server and I have enabled that Any ideas P.S - If there is another way to do it, please let me know My mission is to copy the contents of a folder via "." the dot, rather than read all the files etc. I have my reasons I tried copy("$dir_to_read/$file/.", $dir_to_read); but where I have $dir_to_read it also wants a new file name, so it wont work as there can be several files Quote Link to comment https://forums.phpfreaks.com/topic/102545-solved-system-exec/ Share on other sites More sharing options...
DarkWater Posted April 23, 2008 Share Posted April 23, 2008 Neither command is working? Btw, you don't need the -p flag, because -a is equivalent to -dpR. =) Quote Link to comment https://forums.phpfreaks.com/topic/102545-solved-system-exec/#findComment-525022 Share on other sites More sharing options...
micah1701 Posted April 23, 2008 Share Posted April 23, 2008 have you tried using shell_exec() ? <?php $output = shell_exec("cp -a $dir_to_read/$file/. $dir_to_read"); echo "<pre>$output</pre>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/102545-solved-system-exec/#findComment-525026 Share on other sites More sharing options...
jaymc Posted April 23, 2008 Author Share Posted April 23, 2008 have you tried using shell_exec() ? <?php $output = shell_exec("cp -a $dir_to_read/$file/. $dir_to_read"); echo "<pre>$output</pre>"; ?> No, but I just have and it did not work either Quote Link to comment https://forums.phpfreaks.com/topic/102545-solved-system-exec/#findComment-525036 Share on other sites More sharing options...
jaymc Posted April 23, 2008 Author Share Posted April 23, 2008 Neither command is working? Btw, you don't need the -p flag, because -a is equivalent to -dpR. =) Neither is working, also tried without the p and no joy Quote Link to comment https://forums.phpfreaks.com/topic/102545-solved-system-exec/#findComment-525038 Share on other sites More sharing options...
DarkWater Posted April 23, 2008 Share Posted April 23, 2008 What's the exact exec() line your PHP code? Quote Link to comment https://forums.phpfreaks.com/topic/102545-solved-system-exec/#findComment-525039 Share on other sites More sharing options...
jaymc Posted April 23, 2008 Author Share Posted April 23, 2008 shell_exec("cp -a $dir_to_read/$file/. $dir_to_read"); //exec("cp -a $dir_to_read/$file/. $dir_to_read"); //system("cp -ap $dir_to_read/$file/. $dir_to_read"); //copy("$dir_to_read/$file/.", $dir_to_read); P.S - I have had commands like gunzip unrar etc working with exec just incase you think thats the issue Quote Link to comment https://forums.phpfreaks.com/topic/102545-solved-system-exec/#findComment-525043 Share on other sites More sharing options...
DarkWater Posted April 23, 2008 Share Posted April 23, 2008 shell_exec("cp -a $dir_to_read/$file/. $dir_to_read"); //exec("cp -a $dir_to_read/$file/. $dir_to_read"); //system("cp -ap $dir_to_read/$file/. $dir_to_read"); //copy("$dir_to_read/$file/.", $dir_to_read); P.S - I have had commands like gunzip unrar etc working with exec just incase you think thats the issue shell_exec("cp -a $dir_to_read/$file/\. $dir_to_read"); I think you needed to escape that . after the first location because PHP thinks it's trying to concatenate something. Try this new line. Quote Link to comment https://forums.phpfreaks.com/topic/102545-solved-system-exec/#findComment-525052 Share on other sites More sharing options...
jaymc Posted April 23, 2008 Author Share Posted April 23, 2008 Nice idea, didnt work though Thought you had it then Quote Link to comment https://forums.phpfreaks.com/topic/102545-solved-system-exec/#findComment-525057 Share on other sites More sharing options...
jaymc Posted April 23, 2008 Author Share Posted April 23, 2008 Any more ideas? Quote Link to comment https://forums.phpfreaks.com/topic/102545-solved-system-exec/#findComment-525122 Share on other sites More sharing options...
jaymc Posted April 23, 2008 Author Share Posted April 23, 2008 This worked $exec = "cp -a $dir_to_read/$file/. $dir_to_read"; $output = exec($exec); Thanks to DarkWater for that one Quote Link to comment https://forums.phpfreaks.com/topic/102545-solved-system-exec/#findComment-525296 Share on other sites More sharing options...
DarkWater Posted April 23, 2008 Share Posted April 23, 2008 No problem man. =D I wonder why it didn't work before though... Quote Link to comment https://forums.phpfreaks.com/topic/102545-solved-system-exec/#findComment-525300 Share on other sites More sharing options...
jaymc Posted April 23, 2008 Author Share Posted April 23, 2008 Strange, probably the way php was handling the fullstop, the slash didnt have any effect, infact it probably thought that was part of the filename Quote Link to comment https://forums.phpfreaks.com/topic/102545-solved-system-exec/#findComment-525556 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.