json — PHP итеративные каталоги с функциями ftp_

Ладно, ребята, вот еще один кошмар отладки, с которым я столкнулся и не могу понять, что именно здесь происходит -_-

В основном происходит то, что этот код возвращает JSON в мой запрос ajax. Который изначально включает в себя массив из php.

array(
"public_html"=>
array(
"public_html"=>
array(//...other files actually in public html),
),
0 =>
array(
"filename":".ftpquota",
"filesize": 12kb
),
);

Так что, как вы можете видеть, это создает public_html индекс, затем добавление еще одного с тем же именем с фактическими файлами внутри public_html это не то что я хочу, я хочу оригинал public_html вернуться как файлы в public_html

/*
Iterates over files and directories recursively
*/
function ftpFileList($ftpConnection, $path="/") {
//create general array to pass back later
$files = array();

//grabs the contents of $path
$contents = ftp_nlist($ftpConnection, $path);

//explode the $path to get correct index to fill in
$secondaryPath = explode('/',$path);

//test if the last index in the array is blank
//if it is pop it from the array
if($secondaryPath[count($secondaryPath) - 1] == "")
array_pop($secondaryPath);
//if the array is larger than or equal to one
if(count($secondaryPath) >= 1){

//we will rewrite $secondaryPath to the last index (actual file name)
$secondaryPath = $secondaryPath[count($secondaryPath) - 1];
}else{

//if it isn't anything we'll make it the path that we originally passed
$secondaryPath = $path;
}

//check for contents
if($contents){
//iterate over the contents
foreach($contents as $currentFile) {

//if the current file is not . or .. we don't need that at all
if($currentFile !== "." && $currentFile !== ".."){
//if there is a period in the currentFile this means it's a file not a directory
if( strpos($currentFile,".") == 0 ) {

if($files[""]){
if($secondaryPath == $currentFile)
$files[""][$secondaryPath][] = ftpFileList($ftpConnection, $path.$currentFile.'/');
else
$files[""][$secondaryPath][$currentFile] = ftpFileList($ftpConnection, $path.$currentFile.'/');
}else{
$files[$secondaryPath][] = ftpFileList($ftpConnection,$path.$currentFile.'/');
}

}else{
//here we know the $currentFile is a file
if($currentFile !== "." && $currentFile !== ".."){
//file in the correct index with a new index which is an array with information
$files[$secondaryPath][] = array(
"file"=>$currentFile,//file name
"filesize"=>humanFileSize(ftp_size($ftpConnection,"/".$path.$currentFile)),//human readable file size
"creation_date"=>date("F d Y g:i:sa",ftp_mdtm($ftpConnection,"/".$path.$currentFile)),//date in a human readable format
"full_path"=>"/".$path.$currentFile//full path of the file so we can access this later
);
}
}
}
}
return $files;//return the array
}
}

Я надеюсь, что это частично легко понять, я сделал несколько заметок для целей отладки. Мне нужно перебрать и правильно получить файлы в хорошем файле JSON, чтобы я мог перебрать это с помощью JS. Это сложно отладить с помощью имеющегося у меня интернета и проверить его в IDE, которую я использую, у меня есть только Chromebook. (если кто-нибудь знает хорошее приложение для использования с Chromebook.)

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …