Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

Errata

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Errata

    The following file has Errata pertaining to Chapter 6.

    Errata.pdf
    Last edited by M.Lee; 07-09-2009, 03:21 PM.

  • #2
    Why does the script hardcode the directory separator? In Windows, it's a backslash, so this code is already not portable. And the file name might need to be encoded (safe) before sending to browser. Try this instead:


    define(DS, DIRECTORY_SEPARATOR) ; // ... is / on nix and \ on Windows
    define(BR,'<br>') ;
    $dirName = DS . 'etc';
    $dir = opendir($dirName);

    while ( ($file = readdir($dir)) ) {
    $tempFile = $dirName . DS . $file ;
    $tempFileSafe = htmlentities($tempFile, ENT_QUOTES);
    if (is_dir($tempFile)) {
    echo "Directory: $tempFileSafe", BR;
    } elseif (is_file($tempFile)) {
    echo "File: $tempFileSafe", BR;
    } elseif (is_link($tempFile)) {
    echo "Link: $tempFileSafe", BR;
    } else {
    echo "Unknown: $tempFileSafe", BR;
    }
    }
    closedir($dir);


    Chris
    Last edited by RingerSoftware; 07-11-2009, 08:59 PM.

    Comment


    • #3
      Chapter 6

      Chris,

      You are correct in all of your observations.

      However the point of this sample code was to demonstrate the usage of the is_dir, is_file and is_link. I think we made the statement several times throughout the book that the code samples are not to be confused with production code. This being both from a best practices standpoint and an error handling standpoint.

      Thanks,
      Jeff Olen

      Comment

      Working...
      X