glob function problems

How come it seems php glob can only work with relative path in my site built with Yii?

I got a javascript calling a php code to return a list of image files in a directory in json format.

Javascript code (a code snippet deep in /themes/default/js folder):




		$.get('photostack.php', {album_name:album_name} , function(data) {

			var items_count	= data.length;

			for(var i = 0; i < items_count; ++i){

				var item_source = data[i];

				var cnt 		= 0;

				$('<img />').load(function(){

					var $image = $(this);

					++cnt;

					resizeCenterImage($image);

					$ps_container.append($image);

					var r		= Math.floor(Math.random()*41)-20;

					if(cnt < items_count){

						$image.css({

							'-moz-transform'	:'rotate('+r+'deg)',

							'-webkit-transform'	:'rotate('+r+'deg)',

							'transform'			:'rotate('+r+'deg)'

						});

					}

					if(cnt == items_count){

						$loading.remove();

						$ps_container.show();

						$ps_close.show();

						$ps_overlay.show();

					}

				}).attr('src',item_source);

			}

		},'json');

PHP code (photostack.php under root):




<?php

$album_name = $_GET['album_name'];


$files = glob('images/celebrities/albums/'.$album_name.'/*.{jpg,gif,png}', GLOB_BRACE);


$encode = json_encode($files);

echo $encode;

unset($encode);

This code works fine, but when I add multi-language to the mix, it screws up.

I have my site setup with routing rules so that www.test.com/tw/index.php is actually www.test.com/index.php?lang=tw.

In the case of www.test.com/index.php?lang=tw, it works fine.

In the case of www.test.com/tw/index.php, the glob would try to fetch images from www.test.com/tw/images/…, which does not exists. ( tested this by actually duplicated the image folder under a tw director, and it worked…)

I tried to use absolute path in the glob function:


$files = glob('/images/celebrities/albums/'.$album_name.'/*.{jpg,gif,png}', GLOB_BRACE);

but that breaks everything… It fetches nothing at all in all cases (not sure where it’s trying to fetch from).

Can someone shed a light on what I can do? I tried also play around with the routing rules but failed. Any help would be appreciated.

Not sure why when using absolute paths it wont fetch anything. Doesn’t really make sense.

I know. I’m a bit confused too. I’m looking to see if I can add a routing rule to make sure all tw/images/ entries can go without triggering controller/event, but really am lost on that. All example I see are how to trigger and reroute for controller/event…

I’m not very clear on how routing rules have effect on calls like glob.

or could it be something to do with the javascript calling php?

dont think it has to do with js calling php

A few observations:

On the page, a simple image tag would not work when using www.test.com/tw/ (but works with ?lang=tw)


$thumb = CHtml::image("images/celebrities/albums/$star->folder_name/thumb/thumb.jpg","$star->name", array());

adding the / to make image absolute works though.

and if I change the javascript from:


$.get('photostack.php', {album_name:album_name} , function(data) {

to:


$.get('/photostack.php', {album_name:album_name} , function(data) {

then the first one of the six entries would work (it’s a loop that injects a function to onclick event into each of the six divs to fetch images from a folder using ajax).

The pages are:

www.thesparklespa.com/celebrities

www.thesparklespa.com/tw/celebrities

www.thesparklespa.com/celebrities?lang=tw

I really have no clue how to go on… Anyone?