PHP
  Home arrow PHP arrow Page 4 - Implementing Internet Protocols with PHP
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
PHP

Implementing Internet Protocols with PHP
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 6
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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 continued
    ( Page 4 of 4 )

    Now remember that the file names are returned in an array, so we must break the array down so that it lists the individual files. The foreach loop does exactly that:


    foreach($a as $value){


    Sometimes a directory name is returned instead of a file name, so we need to be able to separate the two. The code below makes that separation by checking whether the returned name contains a dot (.). This is because all file names contain a dot that separate the actual file name from the extension:


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

    $img='images/subpage.gif';

    $open="";


    If there is no dot, then the code proceeds to display the appropriate image and directory name. It also creates a link that enables users to access or open the directory to view its contents:


    }else{

    $img='images/fb.gif';

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

    }


    The remaining code sets up three other links that will enable the user to upload, download, and delete a file from the list or directory. If the listed name belongs to a directory, then only one link is displayed:


    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>';


    }



    The table is then closed and the connection to the FTP server is also closed. Below is an image of what this functions accomplishes:

    Conclusion

    We've completed our project; here are a few final pointers to help keep you out of trouble. Remember to activate the FTP server before running this FTP client. The passwords and usernames that I’ve used here are located in a file called ftpconnect.php. If you are going to store the connection details in this way, make sure that this file is stored outside of your root directory.



     
     
    >>> More PHP Articles          >>> More By David Web
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek