Home arrow PHP arrow Page 4 - Stream Me Up, Scotty! (part 1)

Where Am I? - PHP

PHP4 comes with a bunch of new functions designed to allow FTPconnections over the Web. This article explores the new FTP functions,together with an example of how they can be used to build a browser-basedFTP client.

TABLE OF CONTENTS:
  1. Stream Me Up, Scotty! (part 1)
  2. Out With The Old...
  3. ...In With The New
  4. Where Am I?
  5. GETting It Right
  6. Start Me Up!
  7. Lights! Camera! Action!
  8. Well-Formed Ideas
  9. Appendix: Code Listing
By: Vikram Vaswani, (c) Melonfire
Rating: starstarstarstarstar / 4
November 07, 2000

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
Once logged in to an FTP server, PHP offers a number of functions that can provide system-specific information, together with file and directory information.

First, the ftp_pwd() function comes in very useful if you need to find out where you're currently located in the directory tree.

<? // get current location $here = ftp_pwd($conn); ?>
In case you need to know the operating system that the FTP server is currently running, ftp_systype() will be able to give you this information.

<? // get system type $server_os = ftp_systype($conn); ?>
In case you need to switch passive (PASV) mode on or off, PHP has the ftp_pasv() function, which acts as a toggle switch, turning PASV mode on and off. In case you don't know what passive mode...don't worry about it!

<? // turn PASV on ftp_pasv($conn, 1); ?>
How about a file listing? Well, PHP offers two types of listings - a compact listing containing only file and directory names, and a long listing containing detailed information on file sizes, permissions and timestamps.

The first listing is provided by the ftp_nlist() function, while the second comes via ftp_rawlist(). Both functions require a directory name to be passed as a parameter, and both return the listing as an array. Each element of this array corresponds to one line of text from the listing.

<? // obtain file listing $filelist = ftp_nlist($conn, "."); ?>
And in case you're curious about file sizes, there's a very handy ftp_size() function which returns the size of the specified file in bytes. An important point to be noted here is that this function returns a value of -1 on error - a fact which comes in handy if you're trying to distinguish between files and directories, since this function, when invoked on a directory, typically returns a value of -1. You'll see this technique being used extensively in the example coming up later.

<? // obtain file size of file "data.zip" $filelist = ftp_size($conn, "data.zip"); ?>


This article copyright Melonfire 2000. All rights reserved.

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

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: