Home arrow PHP arrow Page 12 - File And Directory Manipulation In PHP (part 2)

In Process - PHP

Now that you know the basics of reading and writing files, this second segment of our tutorial on the PHP filesystem API takes you into deeper waters, showing you how to copy, delete and rename files; scan directories; work with uploaded files over HTTP; perform pattern matches on file names; and read and write to processes instead of files.

TABLE OF CONTENTS:
  1. File And Directory Manipulation In PHP (part 2)
  2. Stripping It To The Bone
  3. Fertile Fields
  4. Configuring The System
  5. The Right Path
  6. Move It
  7. Beam Me Up
  8. Diving Into Directories
  9. A Pattern Emerges
  10. Purging The Dead
  11. Size Does Matter
  12. In Process
  13. Disk Full
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 65
August 21, 2003

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Just as PHP offers the fopen() and fclose() functions to open and close file handles, there's also the popen() and pclose() functions, which can be used to open uni-directional handles to processes. Once a process handle has been created, data can be read from it or written to it using the standard fgets(), fputs(), fread() and fwrite() file functions.

Consider the following example, which demonstrates by opening a pipe to the "cat" command:


<?php

// open handle to process
$ph = popen("/bin/cat /etc/passwd", "r");

// read process output into variable
$contents = fread($ph, 2096);

// display contents
echo $contents;

// close process
pclose($ph);

?>

As you can see, opening a pipe to a process and reading from it is very similar to opening and reading a file. As with files, the first step is to obtain a handle to the process with popen() - this handle serves as the foundation for all future communication. Once a handle has been obtained, data can be read from, or written to, the handle using the file input/output functions you're already familiar with. The handle can be closed at any time with the pclose() function.

If you need bi-directional communication, PHP 4.3 also offers the new
proc_open() and proc_close() functions, which offers a greater degree of control over process communication.



 
 
>>> More PHP Articles          >>> More By icarus, (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: