UK WEB HOSTING FORUM FOR DISCUSSION ON WEB HOSTING SERVICE AND SUPPORT
LINUX HOSTING WINDOWS HOSTING PACKAGES SHOPPING CART OSCOMMERCE ZEN CART AGORA
ECOMMERCE HOSTING ASP MSSQL FRONTPAGE HOSTING PHP MYSQL HOSTING DISCUSSION FORUM
CPANEL RESELLER HOSTING DEDICATED SERVER VPS HOSTING PLESK VIRTUOZZO
Quick Search
Your forum announcement here!

  UK Web Hosting | Dedicated Server Windows and Linux VPS Forum > Web Hosting and Domains > PHP Hosting

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 21-05-2007, 20:31
borninblood's Avatar
Premium Member
 
Join Date: May 2007
Posts: 106
Default readdir() alphabetically

I was wondering if someone could help me - basically I had some code which worked fine on another server, but on my new eukhost server is performing well somewhat odd.

Basically I am using the readdir() function to read in thumbnailed images and the link to their full sized counterparts.

A simple enough procedure, and on the old server it would do this fine, it would read them alphanumerically from the lowest to highest, however on this new server it is reading them in some bizarre order that I can't really work out.

Is there any way to force the code to read a certain way? (I couldn't find such a parameter) or is there anything else I could do?

I suppose if all else fails, I fire everything into an array, sort the array and then output the results, but I really don't want to have to do that if it can be avoided.

Here is the code I am using...

PHP Code:
$j 0;
$gall $_GET['gall'];
$test "/home/simplyti/public_html/members/i/$gall/";
$dir opendir($test);

while (
$file readdir($dir)) 
{

 if (
$file != "." && $file != ".." && $file !="index.php"
 {
     if(
eregi("t[.]jpg"$file)) 
     {

      
$limage explode("t."$file);
      
$linkimage "$limage[0].$limage[1]";
            if (
$j==3)
            {
            print 
"<tr>";
            
$j 0;
            }
        
      print
"<td><div align='center'><a href='http://www.simplytied.com/members/i/$gall/$linkimage' target='_new'><img src='http://www.simplytied.com/members/i/$gall/$file' border='0' /></a></div><td>";
    
$j++;

    }
  }
}
   
closedir($dir); 
Any help would be greatly appreciated!
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Metal) ||
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Bondage)
Reply With Quote
  #2 (permalink)  
Old 21-05-2007, 20:47
DavidAllen's Avatar
Premium Member
 
Join Date: Jan 2007
Location: Amersham
Posts: 346
Send a message via MSN to DavidAllen Send a message via Skype™ to DavidAllen
Default Get coding!

This from the php manual
Quote:
readdir

(PHP 4, PHP 5)

readdir — Read entry from directory handle
Description
string readdir ( resource $dir_handle )

Returns the filename of the next file from the directory. The filenames are returned in the order in which they are stored by the filesystem.
Parameters

dir_handle

The directory handle resource previously opened with opendir().

Return Values

Returns the filename on success, or FALSE on failure.
Looks like you will have to load it into that array after all - sorry
__________________
David Allen -
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Reply With Quote
  #3 (permalink)  
Old 21-05-2007, 20:49
borninblood's Avatar
Premium Member
 
Join Date: May 2007
Posts: 106
Default

Haha, yeah I seen that but prayed someone had came up with an easy way around it.

I bloody hate arrays!

Cheers!
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Metal) ||
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Bondage)
Reply With Quote
  #4 (permalink)  
Old 21-05-2007, 21:25
DavidAllen's Avatar
Premium Member
 
Join Date: Jan 2007
Location: Amersham
Posts: 346
Send a message via MSN to DavidAllen Send a message via Skype™ to DavidAllen
Default Ok - so try this

Well perhaps i could have been a bit more helpful, so try this:
Quote:
$j = 0;
$linkimage=array();
$linkfile=array();
$gall = $_GET['gall'];
$test = "/home/simplyti/public_html/members/i/$gall/";
$dir = opendir($test);



while ($file = readdir($dir))
{

if ($file != "." && $file != ".." && $file !="index.php")
{
if(eregi("t[.]jpg", $file))
{

$linkfile[$j]=$file;
$j++;
}
}
}
$j=0;
print "tr>";
sort ($linkimage);
$k=count($linkimage);
for ($i=0;$i<$k;$i++) {
$limage = explode("t.", $linkfile[$i]);
$linkimage = "$limage[0].$limage[1]";
if ($j==3)
{
print '/tr>tr>';
$j = 0;
}

print 'td>div align="center">a href="http://www.simplytied.com/members/i/$gall/$linkimage" target="_new">img src="http://www.simplytied.com/members/i/$gall/$linkfile[$i]" border="0" />/a>/div>td>';
$j++;

}
}
}
closedir($dir);
print "/tr>";
or something like that
Regards

Ps had to edit it cos the [code] tags messed up the code - I removed all the < from the print lines to get it to display properly
__________________
David Allen -
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by DavidAllen; 21-05-2007 at 21:38.
Reply With Quote
  #5 (permalink)  
Old 22-05-2007, 21:36
borninblood's Avatar
Premium Member
 
Join Date: May 2007
Posts: 106
Default

Haha, much appreciated! Thank you!

I was about to start writing my own, which would have been pretty much that but hey! cheers dude!
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Metal) ||
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Bondage)
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 00:40.

 

Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by Web Hosting 3.1.0
Copyright © 2001-2008, eUKhost.com. All rights reserved.

 
Site Map

VPS Hosting
VPS Hosting plans

Dedicated Server Hosting
Dedicated Server plans

Business Web Hosting
100% uptime Hosting

Cpanel Hosting
cPanel Shared Hosting

Reseller Hosting
Reseller Web Hosting

Windows Hosting
Windows Shared Hosting

Windows VPS

Windows VPS Hosting

Semi Dedicated Servers
Semi-Dedicated Hosting

Dedicated Server Mirroring
Dedicated Server Mirroring

Webhosting Knowledgebase
Frequently asked Questions

Web Hosting Blog
eUKhost Blog

Web Hosting Support
Support Helpdesk

UK Data Center
eUKhost Datacenter

Web Hosting Forum
eUKhost Forum

Support Tutorials
Online Flash Tutorials

Offsite Back-up Plans
Remote Backup Service

Customer Testimonials
eUK Customer Testimonials


knowledgebase articles

eUKhost.com Services

Pre-Sales Questions
Pre-sales FAQ's

Domain Names
Domain registration FAQ's

cPanel Hosting
cPanel Hosting FAQ's

Windows Web Hosting
Plesk Control Panel

Reseller Hosting
Reseller Hosting FAQ's

VPS Hosting
Virtual Private Server

Semi-Dedicated Servers
Semi-Dedicated FAQ's

Dedicated Servers
Dedicated Server Hosting


popular blog categories


Web Hosting
Website Hosting articles

UK Web Hosting
UK Hosting articles

Dedicated Server Hosting
Dedicated Server guidelines

VPS Hosting
VPS hosting articles

cPanel Hosting
cPanel Hosting articles

Linux Operating System
Linux Operating techniques

Windows Web Hosting
Windows plesk articles