PHP
  Home arrow PHP arrow Page 4 - 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 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.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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 2 hosted by Hostway
    Stay green...Green IT