Prev | Current Page 363 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"

[1] => .. [2] => articles [3] => images
[4] => news [5] => test.php )
The context parameter refers to a stream context. You??™ll learn more about this topic in
Chapter 16.
Executing Shell Commands
The ability to interact with the underlying operating system is a crucial feature of any
programming language. Although you could conceivably execute any system-level
command using a function such as exec() or system(), some of these functions are so
commonplace that the PHP developers thought it a good idea to incorporate them
directly into the language. Several such functions are introduced in this section.
Removing a Directory
The rmdir() function attempts to remove the specified directory, returning TRUE on
success and FALSE otherwise. Its prototype follows:
int rmdir(string dirname)
As with many of PHP??™s file system functions, permissions must be properly set in
order for rmdir() to successfully remove the directory. Because PHP scripts typically
execute under the guise of the server daemon process owner, rmdir() will fail unless
that user has write permissions to the directory. Also, the directory must be empty.
To remove a nonempty directory, you can either use a function capable of executing a
system-level command, such as system() or exec(), or write a recursive function
that will remove all file contents before attempting to remove the directory. Note
that in either case, the executing user (server daemon process owner) requires write
access to the parent of the target directory.


Pages:
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375