Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'directories'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 1 result

  1. For the list_dir.php script, line 42 sets conditions to determine if an item should be written or not. The conditions are: if ( (is_file($search_dir . '/' . $item)) AND ((substr($item, 0, 1) != '.') ) I rewrote the condition to fit my preferences, and I will be referring to my version when asking my question, so if my code is wrong that could be the problem. But to the best of my knowledge, they are equivalent. if (is_file($search_dir . '/' . $item) && sub_str($item, 0, 1) != '.') The conditions are quite obvious, and stated in the text. But when I execute the code, no files are shown, and I checked the HTML to make sure. It is the script. I began debugging and discovered that when I remove the second part of the condition && sub_str($item, 0, 1) != '.' it works fine. That makes sense in a way, because it is less restrictive, but none of my file names begin with a period. And what is odd is that I do not encounter a similar problem with directories. When the same 'second part' of the condition is removed for the directory section, the predicted outcome occurs (the parent '..' and current '.' directories appear). I would like to point out that I am running my server off of my Linux (Ubuntu 11.10) computer - implying that I am not running Windows or Mac OS X. My webroot is the 'php' directory with this path: /var/www/php/ Hypotheses: A permissions issue Code in the book is not applicable to my server's operating system The php.ini file is configured differently than the author's I do not know how to test any of the hypotheses, but I imagine I would be able to test the first one by using chmod, but I do not full understand what 'group' and 'other' mean, or what user PHP is under, or what permissions should be sufficient. The entirety of my script follows. <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="default.css" /> <title>Directory Contents</title> </head> <body> <?php // Set directory name and scan $search_dir = '.'; $contents = scandir($search_dir); // List directories print '<h2>Directories</h2> <ul>'; foreach ($contents as $item) { if (is_dir($search_dir . '/' . $item) && substr($item, 0, 1) != '.') { print '<li>' . $item . '</li>' . "\n"; } } print '</ul>'; // Create table for files print '<h2>Files</h2> <table> <tr> <td>Name</td> <td>Size</td> <td>Modified</td> </tr>'; // List files foreach ($contents as $item) { if (is_file($search_dir . '/' . $item)) // && (sub_str($item, 0, 1) != '.') was removed { $fs = filesize($search_dir . '/' . $item); $lm = date('F, j, Y', filemtime($search_dir . '/' . $item)); print " <tr> <td>$item</td> <td>$fs bytes</td> <td>$lm</td> </tr>"; } } print '</table>'; ?> </body> </html> This HTML is the result of including the second part of the condition: <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="default.css" /> <title>Directory Contents</title> </head> <body> <h2>Directories</h2> <ul><li>css</li> <li>template</li> </ul><h2>Files</h2> <table> <tr> <td>Name</td> <td>Size</td> <td>Modified</td> </tr> I do not know why it does not print code after the foreach statement, or even after the closing php tag.
×
×
  • Create New...