简体   繁体   中英

List full home directory using php on mac os 10.8.2

I wrote a php script to output the content of a directory. It works perfectly with "/usr/local/" for example but impossible to run the same code with "/Users/der_/Pictures/"... The output is: "Failed opening directory /Users/der_/Pictures/ for reading". Checking the permissions for this directory give: owner -der_, group -staff. Thanks. running php 5.4.6... Is it necessary to change permissions to "root"? My answer is "yes": change the directory permissions ie chown user:group myexemple_directory but be careful...

A user profile should NOT have root permissions

This one works for me

#!/usr/bin/php

<?php

if ($handle = opendir('/Users/der_/Pictures')) {
    echo "Content:\n";

    /* This is the correct way to loop over the directory. */
    while (false !== ($entry = readdir($handle))) {
        echo "$entry\n";
    }

    closedir($handle);
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM