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.
blog comments powered by Disqus |
|
|
|
|
|
|
|