Home arrow PHP arrow Page 6 - Stream Me Up, Scotty (part 2)

The Application - PHP

You've already seen how PHP4's FTP functions can help youinteract with files on a remote server. In this article, learn how to usePHP's other file and directory manipulation functions, and build anequivalent application that demonstrates the difference between the twoapproaches.

TABLE OF CONTENTS:
  1. Stream Me Up, Scotty (part 2)
  2. Looking Around
  3. To Create And Destroy
  4. Upsa-daisy!
  5. Remote Control
  6. The Application
By: Vikram Vaswani, (c) Melonfire
Rating: starstarstarstarstar / 2
November 29, 2000

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
Now that you know the various techniques, it's time to build a simple file manager. You can download the complete source code from here - I'll just give you a quick tour through the various sections.

"index.php" sets up the main interface for the applications. On the left side is a list of available functions, while the right side contains a listing of files and directories. Directories can be entered by clicking on them, while files located within the Web server document root can be downloaded by clicking on them (files outside the server root cannot be downloaded). The script "index.php" can accept the parameter $dir, which indicates the directory to be displayed.

All this takes place via two functions, links() and filelist(), which you can see in the file "links.php" - the former sets up the links on the left side, while the latter uses the opendir() and other file information functions to obtain information on the size and permissions of files in the directory. Directories are set up as active hyperlinks - once a directory is clicked, the script "index.php" is called once again, but with a different $dir value.

At any point, you can access the functions on the left side - "upload.php" accepts a file for upload, "mkdir.php" allows you to create a new directory in the current locations, "rmdir.php" reverses the process, and "rmfile.php" allows you to delete one or more files. All these scripts accept a single parameter, $dir, which tells them where their respective actions are to be performed.

It's also possible to download files by turning them into clickable hyperlinks - the application checks to first make sure that the files are in the Web server DocumentRoot, sets a flag if they are, and then turns each file into a hyperlink. Again, there are security implications here - so be careful!

And once you're done, it might be worthwhile to go back to the equivalent file browser we built in the first part of this article. If you compare the two approaches, other things being equal, you'll notice that the HTTP file browser is much faster than the FTP file browser, and also allows more flexibility when manipulating files.

Hopefully, this exercise has helped you gain a clearer idea of PHP's file manipulation capabilities, together with an understanding of what is and what isn't possible. I'm off - but I'll see you soon!

This article copyright Melonfire 2000. All rights reserved.

 
 
>>> More PHP Articles          >>> More By Vikram Vaswani, (c) Melonfire
 

blog comments powered by Disqus
   

PHP ARTICLES

- 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...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap

Dev Shed Tutorial Topics: