Help with PHP in a table...

Discussion in 'Programming' started by Whitey, Aug 14, 2008.

  1. #1
    Hey guys.

    I've spent most of the day re-styling a script for a filehost, and I'm having some bother with the file listings.

    By default when you upload a file, it stays the same name as what it is on your PC, this poses a problem if the filename is really long... seen as it stretches the table out of place.

    Here's what I mean:
    http://91.121.106.164/files.php

    You can see that with really long filenames the table is all over the place.

    Is there a way I can knock down the filename to something like "filename..." where the "..." is the rest of the filename, automatically?

    PHP has been put in the table cells to output the filenames etc, so I couldn't think of a logical way to do this. Here is the source:

    http://pastebin.com/m124eacc0

    I'd appreciate any help, thanks :)
     
    Whitey, Aug 14, 2008 IP
  2. klimu

    klimu Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    add:

    function strtrim($s, $l = 20, $c = '...'){ //s=string.. l=limit.. c=endchar..
    if (strlen($s) <= $l) return $s;
    return substr($s, 0, $l - 3).$c;
    }

    replace with:
    echo "<tr><td align=center bgcolor=#F9F9F9>".$i."</td><td align=left bgcolor=#F9F9F9><a href=\"". $short .$filedata[0]."\" target=\"_blank\">".strtrim($filedata[1])."</a></td><td align=center bgcolor=#F9F9F9>".round($filesize,2)." MB</td>";
     
    klimu, Aug 15, 2008 IP