Jump to content

Recommended Posts

Here is the code I'm using... it is supposed to sort the results in alphabetical order... but it doesn't.

 

<?php
$THUMBNAIL_FOLDER = "_thumbnails";
$HIDDEN_FILES[]	= "Thumbs.db";
$HIDDEN_FILES[] = "index.php";
$HIDDEN_FILES[] = $THUMBNAIL_FOLDER;
$THUMBNAIL_WIDTH = 200;
$THUMBNAIL_HEIGHT = 100;

// Image Output;
HandleImageOutput();

?>
<html>
<head>
<title>Index Of.</title>
<style>
body { background-color: #FCFFF0; font-size: 12px;}
A:link {text-decoration: none; color: blue}
A:visited {text-decoration: none; color: blue}
A:active {text-decoration: none; color: blue}
A:hover {text-decoration: underline; color: blue}

#images, #folders, #files { border: 1px solid #000000; background-color: #fff; margin: 50px; padding: 25px; }


DIV.image { width: <?php echo $THUMBNAIL_WIDTH; ?>; height: <?php echo $THUMBNAIL_HEIGHT; ?>; float: left; margin: 10px; text-align: center; border: 0px; }
IMG { border: 1px solid #444; background-color: #eee; }
</style>
</head>
<body>

<p><br><p><table width=100%><tr width=100%><td width=100%><h2>Title</h2>
<font face=tahoma>

<?php

$Browse = $_GET["b"] ;

if ( $Browse )
{
$Browse .= "/";
}

// Stop them accessing higher level folders
if ( substr_count( $Browse, ".." ) > 0 || substr_count( $Browse, $THUMBNAIL_FOLDER ) > 0  )
{
echo "You don't have permission to access this folder!";
exit();
}

$DIR = "./" . $Browse;
$d = dir( $DIR );

while (false !== ($entry = $d->read())) 
{
if ($entry[0] == '.') continue;
if ( in_array( $entry, $HIDDEN_FILES) ) continue;

// Don't list the folder if it has an index!
if ($entry == 'index.html') exit();
if ($entry == 'index.htm') exit();
if ($entry == 'index.php') exit();
if ($entry == 'index.asp') exit();

if ( IsImage($entry) ) $images[] = array( filemtime( $DIR . "/" . $entry ), $entry );
else if ( is_dir( $DIR . "/" . $entry ) ) $folders[] = array( filemtime( $DIR . "/" . $entry ), $entry );
else $files[] = array( filemtime( $DIR . "/" . $entry ), $entry );

}


if ( count( $folders ) > 0 )
{
echo "<div id=\"folders\">";

arsort($folders);
foreach ( $folders as $fn )
{
	echo "<a href=\"$fn[1]/index.php\">$fn[1]</a><br>";
}

echo "</div>";
}

if ( count( $files ) > 0 )
{
echo "<div id=\"files\">";

arsort($files);
foreach ( $files as $fn )
{
	echo "<a href=\"$Browse$fn[1]\">$fn[1]</a><br>";
}

echo "</div>";
}

if ( count( $images ) > 0 )
{
echo "<div id=\"images\"><div style=\"clear: both;\"></div>";

arsort($images);
foreach ( $images as $fn )
{
	echo GetImageLink( $Browse . $fn[1], $fn[1] );
}

echo "<div style=\"clear: both;\"></div></div>";
}

?>


</body>
</html>

<?

////// FUNCTIONS /////

function IsImage( $i )
{
	$i = strtolower( $i );

	if ( substr_count( $i, ".jpg" ) > 0  ||
		 substr_count( $i, ".jpeg" ) > 0 ||
		 substr_count( $i, ".gif" ) > 0 ||
		 substr_count( $i, ".png" ) > 0 )
	{
		return true;
	}

	return false;
}


function GetImageLink( $imgfilename, $img )
{
	global $THUMBNAIL_WIDTH, $THUMBNAIL_HEIGHT;
	return "<div class=\"image\"><a href=\"$imgfilename\"><img src=\"?img=$imgfilename\" width=$THUMBNAIL_WIDTH height=$THUMBNAIL_HEIGHT></a><br>$img</div>";
}

function HandleImageOutput()
{
	global $THUMBNAIL_FOLDER, $THUMBNAIL_WIDTH, $THUMBNAIL_HEIGHT;

	$image = $_GET['img'];
	if (!$image) return;

	$imagecache = $THUMBNAIL_FOLDER . "/" . md5( $THUMBNAIL_WIDTH . $THUMBNAIL_HEIGHT . $image ) . ".jpg";

	$im = @imagecreatefromjpeg( $imagecache );
	if ( $im )
	{
		header("Content-type: image/jpg");
		imagejpeg($im);							
		imagedestroy($im);					
		exit();
	}

	$imgsize = getimagesize ( $image );

	switch ($imgsize[2]) 
	{
  		case 1: // GIF
    		$im    	= imagecreatefromgif( $image );
    		break;
   		case 2: // JPG
    		$im    	= imagecreatefromjpeg( $image );
    		break;
   		case 3: // PNG
    		$im    	= imagecreatefrompng( $image );
    		break;
    	default: // UNKNOWM!
			echo "Unknown Image!";
    		exit();		
	}

	header("Content-type: image/jpg");

	$img_thumb = imagecreatetruecolor( $THUMBNAIL_WIDTH, $THUMBNAIL_HEIGHT );

	$dsth = ($THUMBNAIL_WIDTH / ImageSX($im)) * ImageSY($im);

	imagecopyresampled( $img_thumb, $im, 0,($THUMBNAIL_HEIGHT-$dsth)/2, 0,0, $THUMBNAIL_WIDTH, $dsth, ImageSX($im), ImageSY($im) );

	imagejpeg( $img_thumb );

	// This will fail if you haven't created and chmodded your thumbnails folder
	if ( $im && $img_thumb )
	{
		@imagejpeg( $img_thumb, $imagecache, 95 );
	}

	imagedestroy( $img_thumb );
	imagedestroy( $im );
	exit();
}
?>

Link to comment
https://forums.phpfreaks.com/topic/205730-thing-wont-alphabetize/
Share on other sites

If you use the button element in an HTML form, different browsers will submit different values. Internet Explorer will submit the text between the <button> and </button> tags, while other browsers will submit the content of the value attribute. Use the input element to create buttons in an HTML form.

I just noticed something that I need to mention.  Using the sorting I have in my code, it actually is sorting... but the sorting is broken up into two groups.  First it runs through the shorter names alphabetically, then it starts over at "A" and runs through the longer names (longer than 8 or so letters) alphabetically... why would it do this?

I shortened the name of one of the longer entries thinking that it would change position in the sort, since they seem to be grouping into the two separate alphabetical groups based on length (one for shorter entires and one for longer ones of 9+ characters), but it stayed in the same position.  So it's not due to length.

 

I really don't get this. I just want the array to sort in alphabetical order. But for some reason, it is separating some of them from the others and then, secondarily, sorting the two groups alphabetically...

Well, I've pretty much narrowed down the problem.  When I make some change to a file in the folder, that folder pops to the top of the list in its parent folder (where I have this php code displaying the contents of that folder).  So it is actually sorting them by the date of the folder's contents.  The partially alphabetical sorting is just due to the fact that they mostly uploaded in that order.

 

ANY help on why it would be doing this would be appreciated...

Well ... you gave us this big long script which we're not familiar with, but didn't give us an example of the array you were trying to sort (both before & after). Sometimes, you have better luck trying to solve a problem yourself, than waiting for a solution from a forum.

 

Ken

Well, it's sad to see that I figured out that the use of filemtime in the array was the problem before the "experts" around here did.

 

/thread

 

With that attitude, I hope you never come here for help with your "scripts" again.

Well, it's sad to see that I figured out that the use of filemtime in the array was the problem before the "experts" around here did.

 

/thread

 

Sorry bostonjim, I was still sleeping.  I'll make sure to get up at the crack of dawn to answer your question.

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.