PDA

View Full Version : Jsonview and php



DarthDie
20 Sep 2007, 10:08 AM
Hey all,
I have a Jsonview that displays images, and it loads get-images.php, I would like get-images.php to look like:

<?
$json = new Services_JSON();

$dir = "images/";
$images = array();
$d = dir($dir);
while($name = $d->read()){
if(!preg_match('/\.(jpg|gif|png)$/', $name)) continue;
//$size = filesize($dir.$name);
//$lastmod = filemtime($dir.$name)*1000;
$images[] = array('name'=>$name, 'size'=>$size,
'lastmod'=>$lastmod, 'url'=>$dir.$name);
}
$d->close();
$o = array('images'=>$images);
echo $json->encode($o);
?>

(Or something similar)
But the jsonview display's no images. It works if get-images.php looks like:

{"images":[{"name":"dance_fever.jpg","shortName":"Dance Fever","url":"images/dance_fever.jpg"},{"name":"gangster_zack.jpg","shortName":"Gangster Zack","url":"images/gangster_zack.jpg"}]}

why? Can anyone help?

DarthDie
20 Sep 2007, 5:05 PM
Anybody? Any tiny suggestion at all? I also wont work if get-images.php looks like:

<?
echo '{"images":[{"name":"dance_fever.jpg","shortName":"Dance Fever","url":"images/dance_fever.jpg"},{"name":"gangster_zack.jpg","sho rtName":"Gangster Zack","url":"images/gangster_zack.jpg"}]}';
?>
(though it wouldnt be multi-line)

Animal
21 Sep 2007, 12:14 AM
Try a PHP forum.

steffenk
21 Sep 2007, 12:33 AM
you hace to collect them in array images:

$images['images'][] = array('name'=>$name, 'size'=>$size,'lastmod'=>$lastmod, 'url'=>$dir.$name);

please use codeboxes, it's really unreadable this way.