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.