我正在构建一个PHP脚本,它将从本地服务器获取某些目录并将它们上载到远程服务器。我正在使用phpseclib来解决这个问题。我试图想到一个一次上传文件的递归函数。目前我正在使用这样的数组:
[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
)
我将循环遍历每个目录顶层的数组的第一部分。从那里我想使用一个函数来递归地将文件添加到删除服务器,其中作为数组的键是目录名称,数组是该目录的内容。列表中第一个数组的几个例子就是这样的:
/local/public_html/14842/adlcp_rootv1p2.xsd => /remote/public_html/14842/adlcp_rootv1p2.xsd
或
/local/public_html/14842/mobile/slides/5VCMBOzQqNC.gz => /remote/public_html/14842/mobile/slides/5VCMBOzQqNC.gz
要构建该数组,我目前有一个我可能能够修改的功能,以便上传文件而不是构建文件但是遇到了一些麻烦。这是循环和功能:
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;
}
如果我需要更多信息以提供帮助,请告诉我们。