Traditional Chinese Big5 directory name display failure...
Posted: Fri Jan 05, 2007 3:47 am
feyd | Please use
buildDirs() is defined in the code section.
Thank you very much in advance!
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi all,
Recently I am trying a free php gallery called Saurdo Gallery. I installed it successful and it is working well. It reads all defined directories and files in them and displays the directory names as well as all the images inside these directories.
Problem occurred when I tried to change a directory name from English to Traditional Chinese Big5. The renamed directory didn't show up in the gallery index page.
I tried the following but [color=red]no success[/color]:
in showDirs() function:Code: Select all
$Dirs = buildDirs(unicode_encode($gallery_root.$currentdir,'BIG5'));
$Dirs = buildDirs(unicode_decode($gallery_root.$currentdir,'BIG5'));
$Dirs = buildDirs(utf8_encode($gallery_root.$currentdir));
$Dirs = buildDirs(utf8_decode($gallery_root.$currentdir));
$Dirs = buildDirs(htmlspecialchars($gallery_root.$currentdir,ENT_QUOTES,BIG5));
$Dirs = buildDirs(htmlentities($gallery_root.$currentdir,ENT_QUOTES,BIG5));Thank you very much in advance!
Code: Select all
<?php
// Globals - Do not tamper with these
global $gallery_root, $gallery_address, $file, $excluded_folders, $pictwidth, $pictheight, $thumbwidth, $thumbheight, $gallery_width;
// ---------- Settings ----------
// Configure these settings, to use the gallery.
// Your gallery folder (this is where your pictures and picture folders are located).
$gallery_address = '/images/photos/';
// Add foldernames to exclude. (add more lines like this on more excludes.)
$excluded_folders[] = 'cgi-bin';
// Picture Preview size
$pictwidth = 600;
$pictheight = 600;
// Thumbnail size
$thumbwidth = 200;
$thumbheight = 200;
// ---------- Settings end ----------
$gallery_root = $_SERVER['DOCUMENT_ROOT'].$gallery_address;
$gallery_address = 'http://'.$_SERVER['HTTP_HOST'].$gallery_address;
function showGallery() {
global $file;
if (!validateFile())
{
echo 'Invalid folder or file';
return;
}
createNavigation();
$path = pathinfo($file);
if ($path['extension'] == '')
{
//Display Dir(s) (if any)
showDirs();
//Display Thumb(s) (if any)
showThumbs();
} else {
showSlide($file);
}
}
function setCurrentdir()
{
global $currentdir, $file;
$path = pathinfo($file);
if ($path['extension'] != '')
$currentdir = $path['dirname'].'/';
else
$currentdir = $file;
}
function [color=red]buildDirs[/color]($Dir) {
if ( substr ( $Dir, -1 ) != '/' ) $Dir .= '/'; // Add a trailing slash
$Handle = opendir($Dir);
$Dirs = array();
while ( false !== ( $File = readdir ( $Handle ) ) )
{
if ( $File == '.' OR $File == '..' OR !is_dir ( $Dir . $File ) ) continue;
$Dirs[] = $File;
}
natcasesort ( $Dirs );
return $Dirs;
}
function [color=red]showDirs()[/color]{
global $gallery_root, $currentdir, $file, $excluded_folders;
$Dirs = buildDirs($gallery_root.$currentdir);
$runonce = false;
foreach ( $Dirs as $dir ) {
if (!in_array($dir, $excluded_folders)) {
if ( !$runonce ){
echo '<div class="folder">Folders:<br/><table class="foldersbox">';
$runonce = true;
}
echo '<tr><td><a href="'.$_SERVER['PHP_SELF'].'?file='.$currentdir.$dir.'/"><img src=./gallery/images/folder.gif> '.$dir.'</a></td></tr>';
}
}
if ( $runonce )
echo '</table></div><br/>';
}
///// Show Slide
function showSlide($slidefile) {
global $gallery_root, $gallery_address, $currentdir, $file;
if ($dir_content = opendir($gallery_root.$currentdir)) {
while ( false !== ($img = readdir($dir_content)) ) {
if ( is_file($gallery_root.$currentdir.$img) && eregi(".*(\.jpg|\.gif|\.png|\.jpeg)", $img))
$imgfiles[] = $img;
}
}
$slide = '';
$arraysize = count($imgfiles);
for ($i=0; $i < $arraysize; $i++)
{
if($currentdir.$imgfiles[$i] == $slidefile)
{
$slide = $imgfiles[$i];
}
}
echo '<div class="image"><a href="'.$gallery_address.$currentdir.$slide.'" target="_new"><img src="./gallery/img.php?file='.$currentdir.$slide.'&thumb=0"></a>
</div>
<br/>
<div class="imgdata"><br/>';
///////////// This is the Exif section
$exif = exif_read_data($gallery_root.$currentdir.$slide, 0, true);
echo "<ul>";
// get file name
echo "<li>Name: <b>" . $exif['FILE']['FileName'] . "</b></li>";
// get file size
if ($exif['FILE']['FileSize'] == null){
echo '';
}else{
echo "<li>File Size: " . floor($exif['FILE']['FileSize']/10.24)/100 . " kbs";
}
// get image dimensions
if ($exif['COMPUTED']['Width'] == null || $exif['COMPUTED']['Height'] == null){
echo '';
}else{
echo "<li>Dimensions: " . $exif['COMPUTED']['Width'] . " x " . $exif['COMPUTED']['Height'] . " </li>";
}
// get timestamp
if($exif['EXIF']['DateTimeOriginal'] == null){
echo '';
}else{
echo "<li>Timestamp: " . $exif['EXIF']['DateTimeOriginal'] . "</li>";
}
// get exposure
if($exif['EXIF']['ExposureTime'] == null){
echo '';
}else{
echo "<li>Exposure Time: " . $exif['EXIF']['ExposureTime'] . "th of a second </li>";
// get Aperture
if($exif['EXIF']['ApertureValue'] == null){
echo '';
}else{
echo "<li>Aperture: " . $exif['EXIF']['ApertureValue'] . "</li>";
}
// get Flash
if($exif['EXIF']['Flash'] == null){
echo '';
}else{
echo "<li>Flash: " . $exif['EXIF']['Flash'] . "</li>";
}
// get Focal Length
if($exif['EXIF']['FocalLength'] == null){
echo '';
}else{
echo "<li>Focal Length: " . $exif['EXIF']['FocalLength'] . "</li>";
}
// get Digital Zoom
if($exif['EXIF']['DigitalZoomRatio'] == null){
echo '';
}else{
echo "<li>Digital Zoom: " . $exif['EXIF']['DigitalZoomRatio'] . "</li>";
}
// get ISO Speed
if($exif['EXIF']['ExposureIndex'] == null){
echo '';
}else{
echo "<li>ISO Speed: " . $exif['EXIF']['ExposureIndex'] . "</li>";
}
// get White Balance
if($exif['EXIF']['WhiteBalance'] == null){
echo '';
}else{
echo "<li>White Balance: " . $exif['EXIF']['WhiteBalance'] . "</li>";
}
}
//////////end exif
'
</ul></div>';
}
//// Displaying thumbs
function showThumbs() {
global $gallery_root, $gallery_address, $currentdir, $file, $thumbwidth, $thumbheight;
if ($dir_content = opendir($gallery_root.$currentdir)) {
while ( false !== ($file = readdir($dir_content)) ) {
if ( is_file($gallery_root.$currentdir.$file) )
if(eregi(".*(\.jpg|\.gif|\.png|\.jpeg)", $file))
$imgfiles[] = $file;
}
}
echo '<div class="image">Images<p>';
if(isset($imgfiles))
{
sort($imgfiles);
foreach ($imgfiles as $img)
{
//echo '<div style="position: relative; width: '.($thumbwidth+16).'px; height: '.($thumbheight+16).'px; border: 1px solid #a9a9a9;">';
echo '<a href="./gallery/img.php?file='.$currentdir.$img.'&thumb=0" class="linkopacity" rel="lightbox['.$currentdir.']" title="View Preview" id="<ul><li>Full sized - <a href='.$gallery_address.$currentdir.$img.' target=_blank>'.$img.'</a></li><li><a href='.$_SERVER['PHP_SELF'].'?file='.$currentdir.$img.' target=_blank>Detailed information</a></li></ul>"><img src="./gallery/img.php?file='.$currentdir.$img.'&thumb=1"></a>';
//echo '</div>';
}
}
echo '</div>';
}
// Validates file variable
function validateFile() {
global $excluded_folders, $file;
$file = $_GET['file'];
// validate dir
if ( strstr($file, '..') || strstr($file, '%2e%2e') )
return false;
foreach ($excluded_folders as $folder)
{
if ( strstr($file, $folder) )
return false;
}
setCurrentdir();
return true;
}
function createNavigation()
{
global $currentdir, $file;
if ($currentdir == './')
$currentdir = '';
$nav = split('/', $currentdir);
array_pop($nav);
$path = pathinfo($file);
echo '<div>Now Viewing: » <a href="'.$_SERVER['PHP_SELF'].'">Gallery</a> ';
foreach ($nav as $n)
{
$current .= $n.'/';
echo '» <a href="'.$_SERVER['PHP_SELF'].'?file='.$current.'">'.$n.'</a> ';
}
if ($path['extension']!='')
echo '» <a href="'.$_SERVER['PHP_SELF'].'?file='.$current.$path['basename'].'">'.$path['basename'].'</a>';
echo '</div><br>';
}
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]