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

Listfiles Function Explained - 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

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
 

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: