Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8709853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:28:26+00:00 2026-06-13T04:28:26+00:00

This is my php code that connects me with another ftp server and shows

  • 0

This is my php code that connects me with another ftp server and shows me the content of it. It then puts the results in a table. However, I want the table to create a new tag after every third entry.
I did try the following :

<html>
<head><title>some crap</title>
<style type="text/css">
<!--
@import url("style.css");
-->
</style>
</head>
<body>
<table id="gradient-style">
    <thead>
        <tr>
            <th colspan='99'>folders</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <td colspan='99'>End</td>
        </tr>
    </tfoot>
    <tbody>
    <tr>
<td>
<?php
$ftpHost = 'xxx';
$ftpUser = 'xxx';
$ftpPass = 'xxx';
$startDir = 'logs';
$n = 0;

if (isset($_GET['file'])) {
    // Get file contents (can also be fetched with cURL)
    $contents = file_get_contents("ftp://$ftpUser:$ftpPass@$ftpHost/$startDir/" . urldecode($_GET['file']));

    // Get mime type (requires PHP 5.3+)
    $finfo = new finfo(FILEINFO_MIME);
    $mimeType = $finfo->buffer($contents);

    // Set content type header and output file
    header("Content-type: $mimeType");
    echo $contents;
}
else {
    $dir = (isset($_GET['dir'])) ? $_GET['dir'] : '';

    $conn = ftp_connect($ftpHost) or die("Could not connect, please refresh in 2 seconds");
    ftp_login($conn, $ftpUser, $ftpPass);

    // change dir to avoid ftp_rawlist bug for directory names with spaces in them
    ftp_chdir($conn, "$startDir/$dir");

    // fetch the raw list
    $list = ftp_rawlist($conn, '');
    reset($list);

    while (list(, $item) = each($list)) {
        if(!empty($item)) {
            // Split raw result into pieces
            $pieces = preg_split("/[\s]+/", $item, 9);

            // Get item name
            $name = $pieces[8];

            // Skip parent and current dots
            if ($name == '.' || $name == '..' || $name == 'index.html')
                continue;
            if($n%3 == 0){echo "<tr>";}
            // Is directory
            if ($pieces[0]{0} == 'd') {
                echo "<a href='?dir={$dir}/{$name}'><strong>{$name}</strong></a><td>";
            }
            // Is file
            else {
                echo "<a href='displayer.php?file={$dir}/{$name}'>{$name}</a><td>";
            }
            $n++;
            }
        }
    }
    ftp_close($conn);
?>
    </tr>
    </tbody>
</table>
</body>
</html>

but I get a weird result click here to see my page
what seems to be wrong in my code ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:28:28+00:00Added an answer on June 13, 2026 at 4:28 am

    You’ve just got some incorrect markup as far as I can see, make sure that each result you echo has a beginning and a closing at the end:

    // Is directory
                if ($pieces[0]{0} == 'd') {
                    echo "<td><a href='?dir={$dir}/{$name}'><strong>{$name}</strong></a></td>";
                }
                // Is file
                else {
                    echo "<td><a href='displayer.php?file={$dir}/{$name}'>{$name}</a></td>";
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the PHP code that acts as 'action' for another HTML page that
I have a line of php code that looks like this: echo <script>$('#edit_errors').html('<h3><em>Please Correct
I've written this short piece of php code that requires 2 variables name and
In my college days I remember a php code that handles errors like this..
I have this code that works well: {livre:empty_name} $.ajax({ url: sent.php, type: post, dataType:
Can anyone convert this curl command that works in command line to php code
I'm makin' a scripting language interpreter using PHP. I have this code in that
I have this code (an example that PHP generates for me)... <select id=outsideBlue3> <option
this is function.php of a wordpress theme that NOD32 says this code have a
In PHP, say that you have some code like this: $infrastructure = mt_rand(0,100); if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.