\n", "#DDC69A" ); // Remove the following "if" statement and contents if upload is not desired! if( $_SERVER["REMOTE_USER"] == "admin" ) { $MAX_SIZE = 25000000; $FILE_MIMES = array( 'image/gif', 'image/jpg', 'image/png', 'text/plain', 'text/html', 'application/pdf', 'application/excel', 'application/msword', 'application/octet-stream' ); $FILE_EXTS = array( '.gif', '.jpg', '.png', '.txt', '.htm', '.php', '.gz', '.tgz', '.zip', '.pdf', '.xls', '.doc', '.reg' ); $url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']); $upload_dir = "./"; $upload_url = $url_dir."/"; $message = ""; function do_upload( $upload_dir, $upload_url ) { $temp_name = $_FILES['userfile']['tmp_name']; $file_name = $_FILES['userfile']['name']; $file_name = str_replace( "\\", "", $file_name ); $file_name = str_replace( "'", "", $file_name ); $file_path = $upload_dir . $file_name; if( $file_name == "" ) { $message = "Invalid File Name Specified!"; return $message; } $result = move_uploaded_file( $temp_name, $file_path ); if( !$result ) $message = "\"$file_name\" was NOT uploaded successfully."; else if( !chmod( $file_path, 0664 ) ) $message = "Change permission to 664 failed."; else if( $result ) $message = "\"$file_name\" was uploaded successfully."; else $message = "Somthing is wrong with uploading the file."; return $message; } if( $_FILES['userfile'] ) { $file_type = $_FILES['userfile']['type']; $file_name = $_FILES['userfile']['name']; $file_ext = strtolower( substr( $file_name, strrpos( $file_name, "." ) ) ); if( $_FILES['userfile']['size'] > $MAX_SIZE ) $message = sprintf( "\"$file_name\" is over %dMB.", $MAX_SIZE / 1000000 ); else if( !in_array( $file_type, $FILE_MIMES ) && !in_array( $file_ext, $FILE_EXTS ) ) $message = "Sorry, \"$file_name\" ($file_type) is not allowed to be uploaded."; else $message = do_upload( $upload_dir, $upload_url ); } } $dir = "./"; // Open a known directory, and proceed to read its contents if( is_dir( $dir ) ) { if( $dh = opendir( $dir ) ) { $count = 0; while( ( $file = readdir( $dh ) ) !== false ) { $perms = fileperms( $dir . $file ); if( ( $perms & 0xC000 ) == 0xC000 ) $info = 's'; // Socket elseif( ( $perms & 0xA000 ) == 0xA000 ) $info = 'l'; // Symbolic Link elseif( ( $perms & 0x8000 ) == 0x8000 ) $info = '-'; // Regular elseif( ( $perms & 0x6000 ) == 0x6000 ) $info = 'b'; // Block special elseif( ( $perms & 0x4000 ) == 0x4000 ) $info = 'd'; // Directory elseif( ( $perms & 0x2000 ) == 0x2000 ) $info = 'c'; // Character special elseif( ( $perms & 0x1000 ) == 0x1000 ) $info = 'p'; // FIFO pipe else $info = 'u'; // Unknown // Owner $info .= ( ( $perms & 0x0100 ) ? 'r' : '-' ); $info .= ( ( $perms & 0x0080 ) ? 'w' : '-' ); $info .= ( ( $perms & 0x0040 ) ? ( ( $perms & 0x0800 ) ? 's' : 'x' ) : ( ( $perms & 0x0800 ) ? 'S' : '-' ) ); // Group $info .= ( ( $perms & 0x0020 ) ? 'r' : '-' ); $info .= ( ( $perms & 0x0010 ) ? 'w' : '-' ); $info .= ( ( $perms & 0x0008 ) ? ( ( $perms & 0x0400 ) ? 's' : 'x' ) : ( ( $perms & 0x0400 ) ? 'S' : '-' ) ); // World $info .= ( ( $perms & 0x0004 ) ? 'r' : '-' ); $info .= ( ( $perms & 0x0002 ) ? 'w' : '-' ); $info .= ( ( $perms & 0x0001 ) ? ( ( $perms & 0x0200 ) ? 't' : 'x' ) : ( ( $perms & 0x0200 ) ? 'T' : '-' ) ); $owner_number = fileowner( $dir . $file ); $owner_array = posix_getpwuid( $owner_number ); if( $owner_array["name"] ) $owner_show = $owner_array["name"]; else $owner_show = $owner_number; $group_number = filegroup( $dir . $file ); $group_array = posix_getgrgid( $group_number ); if( $group_array["name"] ) $group_show = $group_array["name"]; else $group_show = $group_number; $size = filesize( $dir . $file ); $date = filemtime( $dir . $file ); $record = array( "Permission" => "$info", "Owner" => "$owner_show", "Group" => "$group_show", "Size" => $size, "Date" => "$date", "File" => "$file" ); $records[$count] = $record; $count += 1; } if( $_GET["field"] ) $sort_field = $_GET["field"]; // Enter the number of field to sort else $sort_field = "File"; // Enter the number of field to sort if( $_GET["order"] ) $sort_order = $_GET["order"]; // Enter the order of fields to sort else $sort_order = 'ASC'; // Enter the order of fields to sort // Compare function alpha function cmpa( $a, $b ) { global $sort_field; global $sort_order; if( $sort_order == "ASC" ) return strcmp( $a[$sort_field], $b[$sort_field] ); else return strcmp( $b[$sort_field], $a[$sort_field] ); } // Compare function numeric function cmpn( $a, $b ) { global $sort_field; global $sort_order; if( $sort_order == "ASC" ) { if( $a[$sort_field] < $b[$sort_field] ) return 0; else return 1; } else { if( $a[$sort_field] > $b[$sort_field] ) return 0; else return 1; } } // Do the array sorting if( $sort_field == "Date" || $sort_field == "Size" ) usort( $records, 'cmpn' ); else usort( $records, 'cmpa' ); // Output print( "
\n" );
      print( "   \n" );
      print( "    \n" );
      print( "     \n" );
      print( "    \n" );
  
  
      print( "    \n" );
      print( "     \n" );
      print( "    \n" );
  
      print( "    \n" );

      if( $_GET["field"] == "Permission" )
      {
        if( $_GET["order"] == "ASC" )
          print( "     \n" );

      if( $_GET["field"] == "Owner" )
      {
        if( $_GET["order"] == "ASC" )
          print( "     \n" );

      if( $_GET["field"] == "Group" )
      {
        if( $_GET["order"] == "ASC" )
          print( "     \n" );

      if( $_GET["field"] == "Size" )
      {
        if( $_GET["order"] == "ASC" )
          print( "     \n" );

      if( $_GET["field"] == "Date" )
      {
        if( $_GET["order"] == "ASC" )
          print( "     \n" );

      if( $_GET["field"] == "Date" )
      {
        if( $_GET["order"] == "ASC" )
          print( "     \n" );

      if( $_GET["field"] == "Date" && $_GET["order"] == "ASC" )
        print( "     \n" );

      if( $_GET["field"] == "File" )
      {
        if( $_GET["order"] == "ASC" )
          print( "     \n" );
      print( "    \n" );
  
      for( $i = 0; $records[$i]; $i++ )
      {
        if( $records[$i]["File"] != "index.php" && !eregi( '^\.[a-zA-Z0-9]+', $records[$i]["File"] ) )
        {
          print( "    \n" );
          print( "     \n" );
          print( "     \n" );
          print( "     \n" );
          print( "     \n" );
          print( "     \n" );
          print( "     \n" );
          print( "     \n" );
          print( "     \n" );
          print( "    \n" );
        }
        $SIZE += $records[$i]["Size"];
        $DATE += $records[$i]["Date"];
      }
      // Size is a total of the directory
      $SIZE = sprintf( "%' 10s", $SIZE );
      $SIZE = str_replace( " ", " ", $SIZE );
      // Date is an average of the directory
      $DATE = $DATE / $i;
      $DATE = round( $DATE, 0 );
      print( "    \n" );
      print( "     \n" );
      print( "     \n" );
      print( "     \n" );
      print( "     \n" );
      print( "     \n" );
      print( "     \n" );
      print( "     \n" );
      print( "    \n" );
      print( "    \n" );
      print( "     \n" );
      print( "    \n" );
      // Remove the following 10 lines if upload is not desired!
      if( $_SERVER["REMOTE_USER"] == "admin" )
      {
        print( "    \n" );
        print( "     \n" );
        print( "    \n" );
      }
      print( "   
\n" ); $path = getenv( "SCRIPT_NAME" ); $directories = array( "/" ); for( $i = 1, $j = 1; $i < strlen( $path ); $i++ ) { if( $path[$i] == "/" ) { array_push( $directories, $directory ); $directory = NULL; $j++; } $directory .= $path[$i]; } print( "   " ); for( $i = 0; $directories[$i]; $i++ ) { $output .= $directories[$i]; printf( "%s", $output, $directories[$i] ); } print( "\n" ); print( "
\n" ); if( $message ) printf( "   %s\n", $message ); else print( "  \n" ); print( "
\n   Permission\n" ); if( $_GET["order"] == "DESC" ) print( " \n   Permission\n" ); } else print( " \n   Permission\n" ); print( " \n Owner\n" ); if( $_GET["order"] == "DESC" ) print( " \n Owner\n" ); } else print( " \n Owner\n" ); print( " \n Group\n" ); if( $_GET["order"] == "DESC" ) print( " \n Group\n" ); } else print( " \n Group\n" ); print( " \n Size \n" ); if( $_GET["order"] == "DESC" ) print( " \n Size \n" ); } else print( " \n Size \n" ); print( " \n Date\n" ); if( $_GET["order"] == "DESC" ) print( " \n Date\n" ); } else print( " \n Date\n" ); print( " \n \n" ); if( $_GET["order"] == "DESC" ) print( " \n \n" ); } else print( " \n" ); print( " \n" ); else print( " \n" ); print( "  \n" ); print( " \n Filename\n" ); if( $_GET["order"] == "DESC" ) print( " \n Filename\n" ); } else print( " \n Filename\n" ); print( "
\n" ); printf( "   %s \n", $records[$i]["File"], $records[$i]["Permission"] ); print( " \n" ); printf( " %s \n", $records[$i]["File"], $records[$i]["Owner"] ); print( " \n" ); printf( " %s \n", $records[$i]["File"], $records[$i]["Group"] ); print( " \n" ); $formatted = sprintf( "%' 10s", $records[$i]["Size"] ); $formatted = str_replace( " ", " ", $formatted ); printf( " %s \n", $records[$i]["File"], $formatted ); print( " \n" ); printf( " %s\n", $records[$i]["File"], date( "M", $records[$i]["Date"] ) ); print( " \n" ); printf( " %s\n", $records[$i]["File"], date( "j", $records[$i]["Date"] ) ); print( " \n" ); if( date( "Y", time( NULL ) ) == date( "Y", $records[$i]["Date"] ) ) printf( " %s \n", $records[$i]["File"], date( "H:i", $records[$i]["Date"] ) ); else printf( " %s \n", $records[$i]["File"], date( "Y", $records[$i]["Date"] ) ); print( " \n" ); printf( " %s\n", $records[$i]["File"], $records[$i]["File"] ); print( "
\n" ); print( "  \n" ); print( " \n" ); print( "  \n" ); print( " \n" ); print( "  \n" ); print( " \n" ); printf( " %s\n", $SIZE ); print( " \n" ); printf( " %s\n", date( "M", $DATE ) ); print( " \n" ); printf( " %s\n", date( "j", $DATE ) ); print( " \n" ); if( date( "Y", time( NULL ) ) == date( "Y", $DATE ) ) printf( " %s \n", date( "H:i", $DATE ) ); else printf( " %s \n", date( "Y", $DATE ) ); print( "
\n" ); print( "  \n" ); print( "
\n" ); print( "
\n" ); print( "   Upload File:\n" ); print( "
\n" ); print( "
\n" ); print( "
\n" ); closedir( $dh ); } } ?>