I am building a PHP script that will take certain directories from a local server and upload them to a remote server. I am using phpseclib to work on this. I am trying to think of a recursive function that will upload the files one at a time. Currently I am using an array like so:
[14842] => Array
(
[0] => adlcp_rootv1p2.xsd
[attachments] => Array
(
)
[1] => icon_online_training.png
[2] => icon_online_training_10_10.png
[3] => icon_online_training_5_5.png
[4] => ims_xml.xsd
[5] => imscp_rootv1p1p2.xsd
[6] => imsmanifest.xml
[7] => imsmd_rootv1p2p1.xsd
[8] => index_lms.html
[9] => index_lms_html5.html
[10] => ioslaunch.html
[lms] => Array
(
[0] => AICCComm.html
[1] => AICCFunctions.js
[2] => API.js
)
[11] => meta.xml
[mobile] => Array
(
[0] => 5WVFAZ5mwdE_80_DX492_DY492_CX170_CY246.png
[1] => 5WVFAZ5mwdE_80_DX492_DY492_CX170_CY246.swf
[2] => 5WWiJ1xMpse_80_DX800_DY800_CX400_CY193.png
[slides] => Array
(
[0] => 5VCMBOzQqNC.gz
[1] => 5VCMBOzQqNC.js
[2] => 5ZyGS2LfXQu.gz
[3] => 5ZyGS2LfXQu.js
)
[56] => spinner.png
[57] => storyline_compiled.js
)
[12] => story.html
[13] => story.swf
[story_content] => Array
(
[0] => 5WVFAZ5mwdE_80_DX492_DY492.swf
[1] => 5WWiJ1xMpse_80_DX800_DY800.swf
[2] => 5YBVUTyceKY_80_DX380_DY380.swf
[3] => 5eOmKqzCtjp_80_B-30_C-40_RB_P_0_0_830_888_DX610_DY610.swf
[4] => 5kmpqRdjAji_80_DX716_DY716.jpg
[5] => 5mWp2jb2eV7_80_DX330_DY330.swf
[6] => 5qT54mLzsgr_80_DX660_DY660.jpg
[slides] => Array
(
[0] => 5VCMBOzQqNC.swf
[1] => 5ZyGS2LfXQu.swf
[2] => 5cf9K2RD4e2.swf
[3] => 5kTbjeZczQg.swf
)
[33] => story.js
[34] => thumbnail.jpg
)
[14] => story_html5.html
[15] => story_unsupported.html
)
[6703] => Array
(
[0] => a day in the life of a rsa.docx
[attachments] => Array
(
)
[1] => icon_resources.png
[2] => icon_resources_10_10.png
[3] => icon_resources_5_5.png
)
I will loop through the first part of the array for the top level of each directory. From there I would like to use a function that is going to recursively add files to a remove server where the keys that are arrays are the directory name and the array is the contents of that directory. A couple of examples from the first array in the list would be something like this:
/local/public_html/14842/adlcp_rootv1p2.xsd => /remote/public_html/14842/adlcp_rootv1p2.xsd
or
/local/public_html/14842/mobile/slides/5VCMBOzQqNC.gz => /remote/public_html/14842/mobile/slides/5VCMBOzQqNC.gz
To build that array I currently have a function that I may be able to modify so that is uploads the files rather than build a file but have had some trouble. Here is that loop and function for that:
foreach($cids as $c) {
$dirArray[$c] = dirToArray($dir . DIRECTORY_SEPARATOR . $c);
}
function dirToArray($dir)
{
$result = array();
$cdir = scandir($dir);
foreach ($cdir as $key => $value) {
if (!in_array($value, array(".", ".."))) {
if (is_dir($dir . DIRECTORY_SEPARATOR . $value)) {
$result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value);
} else {
$result[] = $value;
}
}
}
return $result;
}
If I need any more information to provide for assistance please let me know.