I am new to PHP so please forgive me if I have silly mistakes or my explanation isn't clear...
I am making a local site that controls a few files and folders. The interface uses Codemines jQuery Form Wizard which sends the input values to my process.php file which runs through a series of 'if' statements based on the input values selected.
I have got my form sending the input values correctly using $_SESSION['siteurl'] = $_POST['siteurl'];
and the first process works fine which is copying the entire contents of a folder from one destination to another (23mb of content)... The next process is supposed to copy another folder into the folder copied in the last step but this doesn't seem to happen because the previous copy process is still underway due to the amount of files being copied.
So my question is, how can I create a pause in between the first copy process and the second (the second copy process only available once the first is completed)?
I have tried using sleep(4000);
and usleep(4000);
with no luck but I simply put that code in between the two process (not sure if that is correct).
Here is the PHP code that I am using as part of my process.php file:
if($_SESSION['cmsbranding'] == 'withbranding'){
mkdir("/user/foldername/foldername/$_SESSION[foldername]/", 0700);
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 directory (can be an FTP address)
$src = "/copythisfolder/";
// Full path to the destination directory
$dst = "/user/foldername/foldername/$_SESSION[foldername]/";
set_time_limit(0);
recurse_copy($src,$dst);
mkdir("/user/foldername/foldername/$_SESSION[foldername]/placesecondfolderinhere/", 0700);
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);
}
sleep(4000);
// Source directory (can be an FTP address)
$src = "/copythisfolder-forsecondprocess/";
// Full path to the destination directory
$dst = "/user/foldername/foldername/$_SESSION[foldername]/placesecondfolderinhere/";
set_time_limit(0);
recurse_copy($src,$dst);
}
I hope this makes sense, please don't hesitate to ask if it doesn't.
PLEASE NOTE:
This is page for managing some basic folder tasks for me alone on a local MAMP server, I understand that copying folders and such is not a good idea for most public web applications. This is simply a management tool for me to run personally.
PS: The if()
statements all work fine, i have only pasted in a segment of the code but the issue is definitely to do with how the copying of the first folder takes to process.
Thank you very much to anyone who takes the time to look at this for me.