Its prototype
follows:
array pathinfo(string path)
280 CHAPTER 10 ?– WORKING WITH THE FI LE AND OPERATING SYSTEM
Consider the following path:
/home/www/htdocs/book/chapter10/index.html
As is relevant to pathinfo(), this path contains three components:
??? Directory name: /home/www/htdocs/book/chapter10
??? Base name: index.html
??? File extension: html
Therefore, you can use pathinfo() like this to retrieve this information:
$pathinfo = pathinfo("/home/www/htdocs/book/chapter10/index.html");
printf("Dir name: %s
", $pathinfo[dirname]);
printf("Base name: %s
", $pathinfo[basename]);
printf("Extension: %s
", $pathinfo[extension]);
?>
This returns the following:
Dir name: /home/www/htdocs/book/chapter10
Base name: index.html
Extension: html
Identifying the Absolute Path
The realpath() function converts all symbolic links and relative path references
located in path to their absolute counterparts. Its prototype follows:
string realpath(string path)
For example, suppose your directory structure assumes the following path:
/home/www/htdocs/book/images/
You can use realpath() to resolve any local path references:
CHAPTER 10 ?– WORKING WITH T HE FILE A ND OPERATING SYSTEM 281
$imgPath = "../../images/cover.gif";
$absolutePath = realpath($imgPath);
// Returns /www/htdocs/book/images/cover.gif
?>
Calculating File, Directory, and Disk Sizes
Calculating file, directory, and disk sizes is a common task in all sorts of applications.
Pages:
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355