Home arrow PHP arrow Page 4 - Implementing Internet Protocols with PHP

Listfiles continued - PHP

PHP has many functions that help us to implement Internet and/or networking protocols. In this article, we will look at how to implement some of those protocols using PHP.

TABLE OF CONTENTS:
  1. Implementing Internet Protocols with PHP
  2. The FTP Application
  3. Listfiles Function Explained
  4. Listfiles continued
By: David Web
Rating: starstarstarstarstar / 6
June 03, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: