PHP list files by name help

Discussion in 'Web Design and Development' started by Macman1993, Apr 19, 2010.

  1. Macman1993 macrumors 6502

    Macman1993

    Joined:
    Nov 23, 2007
    #1
    I wrote this script that lists all files in the current directory and puts them into a grid when writing this I just assumed that it would list them alphabetically since they were listed that way in my ftp client but I realized quickly that they list by the date last modified which is a pain since I want to use this to list all my movies on my server so I can watch them on my iPad without having to store them on the device. I have no idea how to make this list them alphabetically, this script just goes down the list of files and puts them in the grid but I would prefer it did it alphabetically so it would be easier to find files when I have more then 50 in the grid. I'm not sure what to do so could someone help me with this? Note that this puts them into the grid just using nested tables, just wanted to point that out so it would make more sense

    Sorry about the horribly long line of code there what it is meant to do is make a new table within the parent table that displays a link to the file a thumbnail and its name below it.

    Code:
    
    <TABLE BORDER="0" WIDTH=100% HEIGHT=100%>
    	<TABLE BORDER="0" WIDTH=100% HEIGHT="100">
     	 <TR>
     	 
     	 
    <?php
    
    //Open current directory
    $dir = opendir(".");
    $fileCount = 0;
    
    //List files in current directory
    while (($file = readdir($dir)) !== false) {
    	if ($fileCount == 4) {
    		
    		echo "</TR> </TABLE>";
    		
    		echo "<TABLE BORDER='0' WIDTH=100% HEIGHT=100%>    <TABLE BORDER='0' WIDTH=100% HEIGHT=100>      <TR>  ";
    		
    		$fileCount=0;
    	}
    	
      	if ($file != "." && $file !=".." && $file !="test.php") {
      		
      		if (is_dir($file)) {
      			$fileIcon = "..//folder.png";
      		}
      		
      		else {
      			$fileIcon = "../file.png";
      		}
      		
      		
      		echo "<TD WIDTH=25%>     <TABLE BORDER='0' WIDTH=100%>       <TR>      <TD>      <center>     <a href='$file'><img src='$fileIcon' width='150' height='100'></img></a> <br /> <a href='$file'>$file</a>    </center>        </TD>          </TR>       </TABLE>       </td>     ";
      		
      		$fileCount++;
      	}
      }
    closedir($dir);
    ?>
    
    
    
     </TR>
    </TABLE>
    
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA

Share This Page