Custom Directory Listing

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
warwound
-


Joined: 17 Mar 2005
Posts: 9
Location: UK

PostPosted: Sat Mar 19, 2005 12:45 pm    Post subject: Custom Directory Listing Reply with quote

I'm using Abyss to host a website which i access mainly from my mobile phone using GPRS mobile internet.

Some folders have hundreds of files in - midi ringtones for example.
And these folders, with lots of files in them, are causing me problems with the browsers on the phones which access them.
The directory listings that Abyss is producing are too large and result in out of memory errors on the mobile phones.

I've created a script to produce a very minimal directory listing - only filenames and filesizes are output - but this still is producing directory listings which are too large for the mobiles' browser.

So i want a new script which will take a directory listing and produce a series of directory listings over a number of pages - i can then select within the script how many files per directory listing page.

I've searched this forum and spent a while on Google looking but had no success. The only scripts i found produced the required split listings but themselves included to much fancy graphics/tables etc - all the extra graphics and stuff making the page too large or incompatible with mobile browsers.

Can anyone help me with a simple script which will produce directory listings limited to a defined number of files per listing page?
The directory listings produced must also be XHTML compatible and have no fancy graphics or extras.

Thanks for any help.

Martin.
Back to top View user's profile Send private message Visit poster's website
admin
Site Admin


Joined: 03 Mar 2002
Posts: 1332

PostPosted: Sat Mar 19, 2005 2:06 pm    Post subject: Re: Custom Directory Listing Reply with quote

warwound,

Can you please post your script here so that we can use it as a starting point for a better listing script?
Back to top View user's profile Send private message
warwound
-


Joined: 17 Mar 2005
Posts: 9
Location: UK

PostPosted: Sat Mar 19, 2005 3:40 pm    Post subject: Reply with quote

Here is my listing.php script file.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Index of <?php echo $_POST['path']; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<table border="0">
<tr>
<td>Filename</td>
<td>Size</td>
</tr>
<?php
/* Split and get the lines */
$lines = explode("\n", $_POST['files']);
/* For each line do... */
foreach ($lines as $line)
{
/* Split the line and get the file information */
list($name, $url, $size, $date, $mimetype) = explode("\t", $line);
if ($mimetype == "")
$mimetype = "Directory";
echo "<TR><TD><A HREF='" . $url . "'>" . $name . "</A></TD><TD>" . $size . "</TD></TR>";
}
?>
</table>
</body>
</html>

As you can see it's a very (original) simple script with which i've simply removed the unwanted properties from it's echo output line.

Martin.
Back to top View user's profile Send private message Visit poster's website
aprelium-beta
-


Joined: 24 Jun 2004
Posts: 383

PostPosted: Tue Mar 22, 2005 2:56 pm    Post subject: Reply with quote

Here is a modified listing script that supports page navigation:

Code:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Index of <?php echo $_POST['path']; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<table border="0">
<tr>
<td>Filename</td>
<td>Size</td>
</tr>
<?php
/* Split and get the lines */
$files_per_page= 10;
$from = (int)$_ENV['REDIRECT_QUERY_STRING'];
$lines = explode("\n", $_POST['files']);
$files_count = count($lines);
$last_page_from = ($files_per_page * (int)($files_count / $files_per_page));

/* For each line do... */
for ($i=$from; $i<$from+$files_per_page; $i++)
{
$line = $lines[$i];
/* Split the line and get the file information */
list($name, $url, $size, $date, $mimetype) = explode("\t", $line);
if ($mimetype == "")
$mimetype = "Directory";
echo "<TR><TD><A HREF='" . $url . "'>" . $name . "</A></TD><TD>" . $size . "</TD></TR>";
}
?>
</table>

<A HREF="<?php echo $_SERVER['PHP_SELF'] ?>">First page</A> -
<A HREF="<?php echo $_SERVER['PHP_SELF'] . "?" . max(0, ($from -  $files_per_page)) ?>">Previous page</A> -
<A HREF="<?php echo $_SERVER['PHP_SELF'] . "?" . min(($from +  $files_per_page), $last_page_from) ?>">Next page</A> -
<A HREF="<?php echo $_SERVER['PHP_SELF'] . "?" . $last_page_from ?>">Last page</A>

</body>
</html>


_________________
Beta Testing Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
warwound
-


Joined: 17 Mar 2005
Posts: 9
Location: UK

PostPosted: Wed Mar 23, 2005 7:41 pm    Post subject: Reply with quote

Many thanks for your time.

I have to report that the new directory listing script works perfectly with my mobile phone set up.
I have perfected it - lower case tags required for XHTML compatibility.
Added a convert bits to kilobytes function for the filesize output too.
Also added an index page link.

Now trying to access the same pages on my PC using Internet Explorer with WinXP SP2 i get a working page but also a load of debug(?) type error messages.
(In IE options, disable script debugging is ENABLED btw).
A typical error is
'Notice: Undefined index: REDIRECT_QUERY_STRING in $:\$$$$$$$\$$$$$$$ $$$$\www\splitlisting.php on line 40'
Mostly these errors occur on the first and last directory listing pages - maybe variables pointing to non-existing pages?
My website is up and online mostly 24/7 so if you want to see my new script working here's the URL:
http://tempaccess.redirectme.net
(Games and Ringtones folders have enough files to give directory listings).

Here's a copy of my new script then 'splitlisting.php'

<head>
<title>Index of <?php echo $_POST['path']; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<table border="0">
<tr>
<td>Filename</td>
<td>Size(KB)</td>
</tr>
<?php

function convert_from_bytes( $bytes, $to=NULL )
{
$float = floatval( $bytes );
switch( $to )
{
case 'Kb' : // Kilobit
$float = ( $float*8 ) / 1024;
break;
case 'b' : // bit
$float *= 8;
break;
case 'GB' : // Gigabyte
$float /= 1024;
case 'MB' : // Megabyte
$float /= 1024;
case 'KB' : // Kilobyte
$float /= 1024;
default : // byte
}
unset( $bytes, $to );
return( $float );
}

/* Split and get the lines */
$files_per_page= 16;
$from = (int)$_ENV['REDIRECT_QUERY_STRING'];
$lines = explode("\n", $_POST['files']);
$files_count = count($lines);
$last_page_from = ($files_per_page * (int)($files_count / $files_per_page));

/* For each line do... */
for ($i=$from; $i<$from+$files_per_page; $i++)
{
$line = $lines[$i];
/* Split the line and get the file information */
list($name, $url, $size, $date, $mimetype) = explode("\t", $line);
if ($mimetype == "")
$mimetype = "Directory";
$size = convert_from_bytes( $size, 'KB' );
$size = round( $size, 2);
echo "<tr><td><a href='" . $url . "'>" . $name . "</a></td><td>" . $size . "</td></tr>";
}
?>
</table>
<p align="center">
<a href="<?php echo $_SERVER['PHP_SELF'] ?>">First page</a> -
<a href="<?php echo $_SERVER['PHP_SELF'] . "?" . max(0, ($from - $files_per_page)) ?>">Previous page</a> -
<a href="<?php echo $_SERVER['PHP_SELF'] . "?" . min(($from + $files_per_page), $last_page_from) ?>">Next page</a> -
<a href="<?php echo $_SERVER['PHP_SELF'] . "?" . $last_page_from ?>">Last page</a>
<br/>
<a href="../">Return to Index</a>
</p>
</body>
</html>

Any ideas how to patch the errors?

Martin.
Back to top View user's profile Send private message Visit poster's website
Anonymoose
-


Joined: 09 Sep 2003
Posts: 2192

PostPosted: Wed Mar 23, 2005 8:17 pm    Post subject: Reply with quote

Notices aren't the same as errors - if you're just getting a bunch of notices, disable PHP reporting them. Can't remember the line offhand but search the forum for disable php notices and you should be able to sort it.
Back to top View user's profile Send private message
warwound
-


Joined: 17 Mar 2005
Posts: 9
Location: UK

PostPosted: Wed Mar 23, 2005 8:34 pm    Post subject: Reply with quote

Excellent!

A quick edit to PHP.INI and it's perfect on pc and mobile too.

The snip...

Code:
;   - Show all errors, except for notices and coding standards warnings
;
;error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT
;
;   - Show all errors, except for notices
;
;error_reporting = E_ALL & ~E_NOTICE
;
;   - Show only errors
;
;error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR
;
;   - Show all errors except for notices and coding standards warnings
;
error_reporting  = E_ALL & ~E_NOTICE; Show all errors, except for notices


Thanks.

Martin.
Back to top View user's profile Send private message Visit poster's website
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Wed Mar 23, 2005 9:13 pm    Post subject: Reply with quote

warwound

There is a little mistake in your listing in:
Code:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />


The file names and the URLs that are sent to your script are in UTF-8 encoding (Unicode) and not in iso-8859-1. So please change this line to (as it was in our script and as it is recommended in our documentation):

Code:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


Otherwise, you will get display errors when file names contain accentuated latin characters (or non latin characters).
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
warwound
-


Joined: 17 Mar 2005
Posts: 9
Location: UK

PostPosted: Wed Mar 23, 2005 10:28 pm    Post subject: Reply with quote

Right then - i've made the changes that you suggested.

Maybe related to the encoding..

I'm having problems downloading Java games etc to my mobile.
I have MIME types defined and, on my server, i have both the JAR file and a valid JAD file.

I can download the JAD file to my mobile from my server, and it will open and offer to download and install the JAR midlet.
But 0% of the JAR midlet downloads and i get the error message 'Download Failed' on my phone.
Looking through the access logs of my server i see my mobile connected and downloading the JAD file but no sign of a request for the JAR midlet.

I opened some JAD files in Notepad and added the JAR midlet location as an absolute URL and my mobile now proceeds to download and install the JAR midlet.

I have yet to test my server with another model of mobile - i'm using a Motorola A835 presently but should have a Nokia N-Gage within a few days which i will do further tests with.

Having made the enoding changes the situation is the same - no sign that the mobile is looking for the JAR midlet in the correct location.

Any suggestions?

Martin.
Back to top View user's profile Send private message Visit poster's website
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Thu Mar 24, 2005 12:40 am    Post subject: Reply with quote

warwound,

We do not think this is an encoding issue. Can you post here the JAD file that isn't working?
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
warwound
-


Joined: 17 Mar 2005
Posts: 9
Location: UK

PostPosted: Thu Mar 24, 2005 1:15 am    Post subject: Reply with quote

Well here's a sample JAD file that doesn't work.
Code:
Manifest-Version: 1.0
MIDlet-1: BallTerminator, BallTerminator.png, BallTerminator
MIDlet-Name: BallTerminator
MIDlet-Version: 1.0
MIDlet-Vendor: Sun Microsystems
Created-By: 1.3.1 (Sun Microsystems Inc.)
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-1.0
MIDlet-Jar-Size: 20363
MIDlet-Jar-URL: BallTerminator.jar
Nokia-MIDlet-Category: Game


I created all my JAD files with JAD maker so they've all got the same format.

Now here's a JAD file that i've edited to include the absolute URL of the JAR midlet on my PC - in the same folder as the JAD file of course.
Code:
Manifest-Version: 1.0
MIDlet-Name: Amoebas
MIDlet-1: Amoebas, , GameMIDlet
MIDlet-Version: 1.0.2
Created-By: 1.3.1 (Sun Microsystems Inc.)
MIDlet-Vendor: Sumea Interactive Ltd.
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-1.0
Nokia-MIDlet-Category: Game
MIDlet-Jar-Size: 25944
MIDlet-Jar-URL: http://$$mysite$$.no-ip.org/bin/32KB%20or%20smaller/amoebas.jar
Nokia-MIDlet-Category: Game


And with the absolute path the mobile downloads the JAR midlet.

I suspect that the problem is actually an incompatibility with the mobile - a Moto A835. Or maybe just a different implementation of J2ME and how it attempts to action a JAD file.

I shall have a Nokia NGage in the next day or so and suspect the NGage will work perfectly!

I'll post the results of my NGage tests when done.

Martin.
Back to top View user's profile Send private message Visit poster's website
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Thu Mar 24, 2005 1:33 am    Post subject: Reply with quote

warwound,

We're not experts in JAR/JAD deployment, but it seems that the official documentation of Sun is a bit unclear when it comes to the MIDlet-Jar-URL value. They simply say URL. (See http://java.sun.com/j2me/docs/wtk2.1/user_html/Ap_Attributes.html ).

Some sites claim that this URL can be relative or absolute: http://www.wmlscript.it/j2me/api20/javax/microedition/midlet/package-summary.html and http://www.microjava.com/articles/techtalk/midp2_games?PageNo=1 .

But in an article from Sun, they say that when you deploy a MIDlet using a web server, you have to use the full URL: http://developers.sun.com/techtopics/mobility/midp/ttips/wtkota/ :

Quote:

The JAR file's location comes from the MIDlet-Jar-URL property in the descriptor. By default, this value is a relative URL like demos.jar, <b>although when you actually deploy your own application you must change this to the absolute URL of the provisioning web server; for example, http://www.mycompany.com/downloads/demos.jar. </b>

_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Thu Mar 24, 2005 1:34 am    Post subject: Reply with quote

warwound,

We're not experts in JAR/JAD deployment, but it seems that the official documentation of Sun is a bit unclear when it comes to the MIDlet-Jar-URL value. They simply say URL. (See http://java.sun.com/j2me/docs/wtk2.1/user_html/Ap_Attributes.html ).

Some sites claim that this URL can be relative or absolute: http://www.wmlscript.it/j2me/api20/javax/microedition/midlet/package-summary.html and http://www.microjava.com/articles/techtalk/midp2_games?PageNo=1 .

But in an article from Sun, they say that when you deploy a MIDlet using a web server, you have to use the full URL: http://developers.sun.com/techtopics/mobility/midp/ttips/wtkota/ :

Quote:

The JAR file's location comes from the MIDlet-Jar-URL property in the descriptor. By default, this value is a relative URL like demos.jar, although when you actually deploy your own application you must change this to the absolute URL of the provisioning web server; for example, http://www.mycompany.com/downloads/demos.jar.

_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
GustavoDL
-


Joined: 08 Jul 2004
Posts: 16
Location: Malaga (Spain)

PostPosted: Sat Mar 26, 2005 3:54 pm    Post subject: Reply with quote

I'd designed a script that appears to be Abyss default directory list:

Code:
<?php
$adir=opendir(str_replace("\\","\\\\",getcwd()));
$dir=str_replace("\\","/",substr(getcwd(),11,strlen(getcwd())))."/";
echo "<!doctype html public \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
echo "<html>\n<head>\n<title>Index of ".$dir."</title>\n</head>\n<body>\n";
echo "<h1>Index of ".$dir."</h1>\n";
echo "<pre>\n<table width=600>\n\t<tr><td width=40%>Name</td><td>Size</td><td>Date-Time</td><td>Type<td><tr><td colspan=4><hr></td></tr><tr>\n\t";
while (false !== ($arch = readdir($adir))) {
   if($arch!='.' && $arch!='index.php'){
      echo "<tr><td><a href=".rawurlencode($arch).">".ucfirst($arch)."</a></td><td align=right>";
      if (filesize($arch)>0) echo number_format(filesize($arch));
      else echo "--";
      echo "</td><td align=center>".date ("d/m/Y H:i:s", filemtime($arch))."</td><td>";
      switch (filetype($arch)){
         case "dir": echo "Directory";break;
         case "file": echo "Archive";break;
         }
      echo "</td></tr>\n\t";
      clearstatcache();
      }
   }
echo "</table>\n</pre>\n<p><hr><b><i>".$_ENV['SERVER_SOFTWARE']."</i></b>\n<br>&copy; <a href=http://www.aprelium.com><a href=http://www.aprelium.com>Aprelium Technologies</a> - 2001-2005</p>\n</body>\n</html>";
closedir($bdir);
?>


If I want to get a directory listed I only have to call this script:
Code:
<?php
include $_SERVER['DOCUMENT_ROOT']."\\cgi\\scriptname.php";
?>

(note that i'm using windows server
_________________
Think as WAN, act as LAN
Piensa en WAN, actua en LAN
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group