Jump to content

[SOLVED] What's the difference....


RhysAndrews

Recommended Posts

There must be a difference between:

md5($_SESSION['email']);

 

and a string of what it returns.

 

Because I am using an ajax gallery, and when I set the address of the photos (in a variable) to:

$gallery_address = '/userdata/' . md5($_SESSION['email']) . '/';

 

the files are found but the images won't show. However, if I set it to:

$gallery_address = '/userdata/f7bfdabc43ff57bcfa425733a8651032/';

 

Where "f7bfdabc43ff57bcfa425733a8651032" is the exact same hash as what  md5($_SESSION['email']) returns, the gallery shows the images fine. I've tried placing md5($_SESSION['email']) in a separate variable and placing the variable in the gallery address instead, and it has the same problem.

 

Help appreciated!

-Rhys

 

 

 

 

Link to comment
Share on other sites

Just tried the trim - that didn't make a difference either. Here's the gallery script. I use saurdo gallery, so if you want all the scripts just download it or ask me =]

 

-Rhys

 

<?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 = '/userdata/'.trim(md5($_SESSION['email'])).'/';


// 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 = 80;
$thumbheight = 80;
// ---------- 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 buildDirs($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 showDirs() {
    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"><IMG src="images/subhead_albums.png" alt="Albums"><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/>';


			'
	</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"><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>Photo Code - '.substr($img,0,-4).'</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><a href="'.$_SERVER['PHP_SELF'].'">Gallery</a> ';
echo '<div>';
    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>';
}
?>

Link to comment
Share on other sites

Ok i need a view more bits;

 

Are you using <?php session_start(); ?> at the top of your script.

can you post a snippet of html output showing the

 

    <a href="./gallery/img.php?file='.$currentdir.$img.'&thumb=0" class="linkopacity" rel="lightbox['.$currentdir.']" title="View Preview" id="<ul><li>Photo Code - '.substr($img,0,-4).'</a></li></ul>"><img src="./gallery/img.php?file='.$currentdir.$img.'&thumb=1"></a>

 

and can u post img.php script

 

and in img.php are you using

 

header("Content-type: image/".substr($file,strlen($file)-4,4)."); // or whatever suits

print $file;

exit;

Link to comment
Share on other sites

<?php
require 'logcheck.php';
require('./gallery/gallery.php'); //Load the gallery scripts

if($loggedin==0)
{
header("location: index.php"); //redirect to the index
}?>

This is the code I use. logcheck.php is irrelevant (it had the same issues when a majority of logcheck.php didn't exist).

 

I use this code to show the gallery where I want on the page:

<DIV id='gallery'><?php if ($loggedin==1) showGallery();?></DIV>

 

This is img.php:

<?php
require('./gallery.php');

generateImg($_GET['file'], $_GET['thumb']);

function generateImg($img, $thumb) {

global $gallery_root, $pictwidth, $pictheight, $thumbwidth, $thumbheight;

if($thumb) {
$height = $thumbheight;
$width = $thumbwidth;
} else {
$height = $pictheight;
$width = $pictwidth;
}

$img = $gallery_root.$img;
$path = pathinfo($img);
switch(strtolower($path["extension"])){
	case "jpeg":
	case "jpg":
		Header("Content-type: image/jpeg");
		$img=imagecreatefromjpeg($img);
		break;
	case "gif":
		Header("Content-type: image/gif");
		$img=imagecreatefromgif($img);
		break;
	case "png":
		Header("Content-type: image/png");
		$img=imagecreatefrompng($img);
		break;
	default:
		break;			
}
$xratio = $width/(imagesx($img));
$yratio = $height/(imagesy($img));

if($xratio < 1 || $yratio < 1) {
	if($xratio < $yratio)
		$resized = imagecreatetruecolor($width,floor(imagesy($img)*$xratio));
	else
		$resized = imagecreatetruecolor(floor(imagesx($img)*$yratio), $height);

	imagecopyresampled($resized, $img, 0, 0, 0, 0, imagesx($resized)+1,imagesy($resized)+1,imagesx($img),imagesy($img));

	imagejpeg($resized);
	imagedestroy($resized);
}
else
{
	imagejpeg($img);
}
imagedestroy($img);		
}
?>

I wouldn't be surprised if the source of the issue was in img.php. Thanks for your help!

 

-Rhys

 

 

Link to comment
Share on other sites

can you post a snippet of html output showing the

 

    <a href="./gallery/img.php?file='.$currentdir.$img.'&thumb=0" class="linkopacity" rel="lightbox['.$currentdir.']" title="View Preview" id="<ul><li>Photo Code - '.substr($img,0,-4).'</a></li></ul>"><img src="./gallery/img.php?file='.$currentdir.$img.'&thumb=1"></a>

Right here:
<a href="./gallery/img.php?file=dmkchhkctu.jpg&thumb=0" class="linkopacity" rel="lightbox[]" title="View Preview" id="<ul><li>Photo Code - dmkchhkctu</a></li></ul>"><img src="./gallery/img.php?file=dmkchhkctu.jpg&thumb=1"></a>

(dmkchhtctu.jpg exists)

Link to comment
Share on other sites

I've played around and I cant reproduce your error, it seems to work fine for me.

Try these :

1)DOUBLE check you have session_start(); in each file and at the very top of the files

2)make sure your $gallery_root var in img.php is pointing at the correct folder

3)!!!! make sure gallery.php which is called at the top of img.php has no html output, any output even ascii can case gd to crash, try putting in static vars and comment out require gallery.php see if that fixes anything

 

let me know how you get on , worse case (cos this is buggin me know ) i'll take a zip of the code and fix it. ;)

Link to comment
Share on other sites

Woe mama!

Thanks dawsba - I just placed session_start() at the top of gallery.php and img.php and it's all fine and dandy now.

I think it was img.php that was the problem, because gallery.php detects the files and it did so with no issues, but img.php couldn't display them.

 

You've solved a big problem of mine! Thanks!

-Rhys

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.