Alex Coronas
Alex Coronas

Reputation: 446

Random <br> being generated

I have a .php file that generates a table based on a directory's content. But for some reason it also generates <br> tags before the table, the more contents inside the directory the more <br> tags.

Here's the code responsible of this:

<main class="mdl-layout__content" style="background-color: white; background-image: url('https://i.warosu.org/data/tg/img/0357/97/1414469732022.gif'); background-size: auto 100%; background-repeat: no-repeat; background-position: center;">
    <center>
      <div class="page-content" style="padding: 24px; align-items: center; justify-content: center;">

        <?php
        echo "<div>\n";
        echo "<table class=\"mdl-data-table mdl-js-data-table mdl-shadow--2dp\" style=\"min-width:300px\"\n";
        echo "  <thead>\n";
        echo "    <tr>\n";
        echo "      <th class=\"mdl-data-table__cell--non-numeric\">File</th>\n";
        echo "      <th>Size</th>\n";
        echo "    </tr>\n";
        echo "  </thead>\n";
        echo "  <tbody>";

        if ($path) echo '<tr><td colspan="2" style="text-align:center"><a href="?file='.urlencode(substr(dirname($root.$path), strlen($root) + 1)).'">..</a></td></tr><br />';
        foreach (glob($root.$path.'/*') as $file) {
            $file = realpath($file);
            $link = substr($file, strlen($root) + 1);
            if (is_dir($file)){
                echo '<tr><td style="text-align:center; vertical-align:middle"><a href="?file='.urlencode($link).'"><i class="material-icons" style="vertical-align:middle">folder</i></a></td><td style="text-align:center; vertical-align:middle"><span style="vertical-align:middle"><a href="?file='.urlencode($link).'">'.basename($file).'</a></span></td></tr><br />';
            }
            else {
            	$lastpath = path2url($file);
                $size = formatSizeUnits(filesize($file));
                echo '<tr><td><a href="'.$lastpath.'">'.basename($file).'</a></td><td>'.$size.'</td></tr><br />';
            }
        }
        ?>
    </tbody>
</table>
</div>
</center>
<button class="show-modal mdl-button mdl-js-button mdl-button--fab mdl-js-ripple-effect mdl-button--colored" id="cornerbutton">

  <i class="material-icons">add</i>

</button>
  <dialog class="mdl-dialog">
    <div class="mdl-dialog__content">
    <form enctype="multipart/form-data" action="upload_file.php" method="POST">
      	<input type="hidden" name="MAX_FILE_SIZE" value="1000000000000" />
      	Choose a file to upload: <input name="uploadedfile" type="file" /><br />
    </div>
    <div class="mdl-dialog__actions mdl-dialog__actions--full-width">
      <input type="submit" class="mdl-button" value="UPLOAD" ></button>
      <button type="button" class="mdl-button close">ABORT MISSION!!</button>
    </div>
    </form>
  </dialog>
</main>

Help

Upvotes: 0

Views: 378

Answers (1)

Lovepreet Singh
Lovepreet Singh

Reputation: 4840

There are br tag added to end of some lines like

echo '<tr><td><a href="'.$lastpath.'">'.basename($file).'</a></td><td>'.$size.'</td></tr>*<br />*'; 

Just remove those.

Upvotes: 1

Related Questions