+ Reply to Thread
Results 1 to 3 of 3

Thread: Errata

  1. #1
    M.Lee Guest

    Default Errata

    The following file has Errata pertaining to Chapter 6.

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

  2. #2

    Default

    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 at 08:59 PM.

  3. #3

    Default 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

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts