PHP
  Home arrow PHP arrow Page 3 - Implementing Internet Protocols with P...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Implementing Internet Protocols with PHP
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2008-06-03

    Table of Contents:
  • Implementing Internet Protocols with PHP
  • The FTP Application
  • Listfiles Function Explained
  • Listfiles continued

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Implementing Internet Protocols with PHP - Listfiles Function Explained


    (Page 3 of 4 )

    Next we define a commonly used function. The function is contained in a file called “functions.php.” It defines a function called listfiles(). This function takes two arguments: the connection resource and the directory. Please, take a look:


    <?php

    //list files

    function listfiles($con,$directory){

    echo '<table>';

    echo '<tr>

    <td></td>

    <td>'.ftp_pwd($con).'</td>

    </tr>

    <tr>

    <td><b>File Name</b></td>

    <td><b>Action</b></td>

    </tr>';


    $a = ftp_nlist($con, $directory);


    foreach($a as $value){

    if(strpos($value,'.') > 0){

    $img='images/subpage.gif';

    $open="";

    }else{

    $img='images/fb.gif';

    $open='<a href="'.$_SERVER['PHP_SELF'].'?action=view&dirs='.$value.'"><img src="images/open.png" border="0">Open</a>';

    }



    echo '<tr class="block">';


    if($open==""){

    echo '<td><img src="'.$img.'" border="0">'.trim($value).'

    </td>

    <td><a href="'.$_SERVER['PHP_SELF'].'?action=upload&file='.$value.'"><img src="images/upload.bmp" border="0"></a>|<a href="'.$_SERVER['PHP_SELF'].'?action=download&file='.$value.'"><img src="images/download.png" border="0"></a>|<a href="'.$_SERVER['PHP_SELF'].'?action=delete&file='.$value.'"><img src="images/trash.png" border="0"></a>


    </td>';

    }else{

    echo '<td><img src="'.$img.'" border="0">'.trim($value).'</td><td>

    '.$open.'';


    echo '</td>';

    }

    echo '</tr>';


    }


    // close the connection

    //ftp_close($con);


    echo '</table>';

    }



    ?>


    The function starts by building a dynamic table with the headers File and Action:

    echo '<table>';

    echo '<tr>

    <td></td>

    <td>'.ftp_pwd($con).'</td>

    </tr>

    <tr>

    <td><b>File Name</b></td>

    <td><b>Action</b></td>

    </tr>';




    Then it calls the ftp_nlist() function to list the files in the given directory. It then stores the result in a variable called $a:


    $a = ftp_nlist($con, $directory);

    More PHP Articles
    More By David Web


       · Dear, i think this article about ftp-client based on ftp-functions, not about...
       · i agree that had nothing to do with protocol, but it was nice to see how to use...
     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT