php - Build JSON directory list -


i have been using arrays , using json_encode, have problem need use multidimensional arrays build json string correctly.

the problem memory. might imagine, having array every single file in directory, meaning have hundreds of arrays inside 1 array, isn't cheap on memory.

my question is, there different way? have following array structure:

array(array("key" => "value"),array("key" => "value"))

why not modify following code, such name attribute renamed src? guess you'd have no need size attribute either.

<?php class mfile {     public $name, $time, $size; }  foreach (glob("*.*") $curfilename) {     $curfileobj = new mfile;     $curfileobj->name = $curfilename;     $curfileobj->time = date("d/m/y - h:i", filectime($curfilename));     $curfileobj->size = filesize($curfilename);     $filearray[] = $curfileobj; } printf("%s", json_encode($filearray)); ?>  

edit: sample output

[{"name":"001-deleteme.html","time":"26/09/2012 - 00:09","size":15062},{"name":"001-test.html","time":"18/10/2012 - 04:29","size":2981},{"name":"001.html","time":"02/10/2012 - 01:26","size":2596}]


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -