I have a file with file paths that is 802,876 lines, each line having a file path and info. I tried using the code here: PHP multidimensional array representing filepath and other code I found, but none work with my file, when using the whole file I get the error:
PHP Fatal error: [] operator not supported for strings in /root/test.php on line 39
When I use a sample of the lines where this error is occurring, my output from the function is just empty. The code i'm using is:
<?php
ini_set('memory_limit', '1024M');
$fd = fopen ("results.txt", "r");
while (!feof ($fd))
{
$buffer = fgets($fd, 4096);
$lines[] = $buffer;
}
fclose ($fd);
$aryBackupData = parse_paths_of_files($lines);
unset($lines);
function parse_paths_of_files($array)
{
$result = array();
foreach ($array as $strFileLineData)
{
if(strpos($strFileLineData,"^") !== false) {
$aryFileLineData = explode("^",$strFileLineData);
if(substr($aryFileLineData[0],0,1) == "d")
$strType = "1"; // Folder/Directory
else
$strType = "2"; // File
$strItemPath = $aryFileLineData[2];
if(strpos($strItemPath,"/") !== false) {
$strItemPath = substr_replace($strItemPath, $strType, strrpos($strItemPath,"/")+1, 0);
$parts = explode('/', $strItemPath);
$current = &$result;
for ($i = 1, $max = count($parts); $i < $max; $i++)
{
if (!isset($current[$parts[$i-1]]))
{
$current[$parts[$i-1]] = array();
}
$current = &$current[$parts[$i-1]];
}
$current[] = $parts[$i-1];
}
}
}
return $result;
}
?>
Here are the sample lines from the file that is causing an issue and I cant see why it is:
-rw-r--r--^Fri, 2018-01-19 07:07:40^var/www/vhtdocs/userweb12345/html/wp-content/uploads/gravity_forms/21-3d41a48e11dac6f966264ca0771ad7e1/2016/index.html
drwxr-xr-x^Tue, 2016-11-01 03:46:47^var/www/vhtdocs/userweb12345/html/wp-content/uploads/gravity_forms/21-3d41a48e11dac6f966264ca0771ad7e1/2016/11
-rw-r--r--^Fri, 2018-01-19 07:07:40^var/www/vhtdocs/userweb12345/html/wp-content/uploads/gravity_forms/21-3d41a48e11dac6f966264ca0771ad7e1/2016/11/index.html
-rw-r--r--^Tue, 2016-11-01 03:46:47^var/www/vhtdocs/userweb12345/html/wp-content/uploads/gravity_forms/21-3d41a48e11dac6f966264ca0771ad7e1/2016/11/Informe-Alternativo-NNA-Ecuador.pdf
drwxr-xr-x^Mon, 2016-10-31 08:21:15^var/www/vhtdocs/userweb12345/html/wp-content/uploads/gravity_forms/21-3d41a48e11dac6f966264ca0771ad7e1/2016/10
-rw-r--r--^Fri, 2018-01-19 07:07:40^var/www/vhtdocs/userweb12345/html/wp-content/uploads/gravity_forms/21-3d41a48e11dac6f966264ca0771ad7e1/2016/10/index.html
-rw-r--r--^Mon, 2016-10-31 07:45:18^var/www/vhtdocs/userweb12345/html/wp-content/uploads/gravity_forms/21-3d41a48e11dac6f966264ca0771ad7e1/2016/10/Informe-Alternativo-Ecuador.docx
-rw-r--r--^Mon, 2016-10-31 08:21:15^var/www/vhtdocs/userweb12345/html/wp-content/uploads/gravity_forms/21-3d41a48e11dac6f966264ca0771ad7e1/2016/10/Alternative-Report-English.docx
drwxr-xr-x^Fri, 2016-12-09 06:14:23^var/www/vhtdocs/userweb12345/html/wp-content/uploads/gravity_forms/21-3d41a48e11dac6f966264ca0771ad7e1/2016/12
-rw-r--r--^Fri, 2018-01-19 07:07:40^var/www/vhtdocs/userweb12345/html/wp-content/uploads/gravity_forms/21-3d41a48e11dac6f966264ca0771ad7e1/2016/12/index.html
-rw-r--r--^Fri, 2016-12-09 06:14:26^var/www/vhtdocs/userweb12345/html/wp-content/uploads/gravity_forms/21-3d41a48e11dac6f966264ca0771ad7e1/2016/12/Consultation-Children-and-adolescents.pdf
drwxr-xr-x^Wed, 2017-03-01 08:40:37^var/www/vhtdocs/userweb12345/html/wp-content/uploads/gravity_forms/21-3d41a48e11dac6f966264ca0771ad7e1/2017