actually my code is displyed var/www/html / folder contents only displayed on gui,
i want to display the /home/Desktop folder contents on gui,,,.......
plz any one help me.......

Dani AI

Generated

Short summary: can list files from /var/www/html but the same PHP script fails on /home/Desktop/songs with "Unable to open folder(/home/Desktop/songs)". That error almost always means the Apache/PHP process cannot reach or read that path — not a PHP bug in opendir. Common causes are filesystem traversal/ownership bits on the parent directories, PHP restrictions (open_basedir), or distro-level confinement (SELinux/AppArmor).

Quick checks to run (on the server) and a tiny PHP test to run in the browser. Look for which user Apache runs as, check the permission bits on every parent directory, and see PHP config (open_basedir). Example PHP test you can place in a file under your DocumentRoot and open in the browser:

<?php
$path = '/home/youruser/Desktop/songs';
echo 'is_dir: '.(is_dir($path)?'yes':'no')."<br>\n";
echo 'is_readable: '.(is_readable($path)?'yes':'no')."<br>\n";
echo 'open_basedir: '.ini_get('open_basedir')."<br>\n";
phpinfo(); // remove when done
?>

If the PHP test shows the directory is not readable or open_basedir is set, that explains the error.

How to fix safely (don’t use world-writable unless you really know what you’re doing): give the Apache user access without opening everything up.

  • Find Apache user (Debian/Ubuntu: www-data, RHEL/CentOS: apache) and either change group ownership and perms:
    • sudo chgrp -R www-data /home/youruser/Desktop
    • sudo chmod -R 750 /home/youruser/Desktop
    • ensure parent dirs are searchable: sudo chmod g+x /home/youruser
  • Or give just that user access with ACLs (safer):
    • sudo setfacl -R -m u:www-data:rx /home/youruser/Desktop
    • sudo setfacl -d -m u:www-data:rx /home/youruser/Desktop

If you run SELinux, enable homedir access and set proper context:

  • sudo setsebool -P httpd_enable_homedirs 1
  • sudo chcon -R -t httpd_sys_content_t /home/youruser/Desktop

You can also add an Apache <Directory> entry that grants access or move the files into /var/www/html. As suggested, permissions/ownership are the key; asked about chgrp/chown — the commands above show how. Avoid 777 for security (as others warned) and remove diagnostic phpinfo() when finished.

Recommended Answers

All 12 Replies

What GUI are you talking about? Please provide some additional details.

i displayed /var/www/html/ folder contents in mozilla firefox but i want to displayed /home/Desktop folder contents in the mozilla firefox ......................................plz help me................

How did you display the folder's content ?

<?php

$path = "/var/www/html/songs/";
here is the above path folder contents are displayed.........

but....

//$path = "/home/Desktop/songs/";
 i want to display this path folder contents in browser......
$dir_handle = @opendir($path) or die("Unable to open folder($path)");
echo "<table>";
while (false !== ($file = readdir($dir_handle))) {

if($file != '.' && $file != '..' && $file != 'Thumbs.db')
{
echo"<tr>";
echo "<td><input type=CHECKBOX name=$file></td>";
echo "<td><img src='small/$file' alt='$file'></td>";
echo"<tr/>";
}
}
echo"</table>";
closedir($dir_handle);

?>

Does the user or group have permissions to access that folder?

ya!.............. i given fill permissions for that folder..........like this(chmod -R 777 foldername/dir name

Do you get an error message ?

message comes like this Unable to open folder(/home/Desktop/songs)

Then the rights are not set correctly. You may have to use chgrp or chown. Perhaps the Apache forum is better suited for this.

My be You need to have a root account.or change permission of the foleder

still i am not getting the o/p, how to i give permissions for that group using(chgrp,chown)

Perhaps the Apache forum is better suited for this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.