Jump to content

How to hide .AppleDouble folder?


tigertim

Recommended Posts

Hi

 

Sorry if this is the wrong place for this but I'm totally stumped here and I know its a basic question but I'm very new to php and I need help :-)

 

Basically all i would like to do is hide certain file types, folders (specifically the folder .AppleDouble) and hidden files, below is my code so far and I'd really appreciate it if anyone could help me out by taking a look! Any help would be very gratefully received!

 

Here's my code so far:

 

<?

 

$rootdir = "../media/Documents";

 

function printdir($dir) {

 

$dircount = 0;

$filecount = 0;

 

$handle = opendir($dir);

while (false != ($file = readdir($handle)))

{

if (@filetype($dir . "/" . $file) == "dir" AND $file != "." AND $file != "..")

{

$dirlist[$dircount] = $file;

$dircount++;

}

else {

if (strtolower(substr($file, -4)) == ".avi")

{

$filelist[$filecount] = substr($file, 0, (strlen($file)-4));

$filecount++;

}

}

 

}

closedir($handle);

 

if ($dircount>0) {sort ($dirlist);}

if ($filecount>0) {sort ($filelist);}

 

for ($i = 0; $i < $dircount; $i++) {

echo "<dl>\n";

echo "<dt><B>" . $dirlist[$i] . "</B></dt>\n";

flush();

printdir($dir . "/" . $dirlist[$i]);

echo "</dl>\n\n";

}

 

for ($i = 0; $i < $filecount; $i++) {

echo "<dd>" . $filelist[$i] . "</dd>\n";

flush();

}

if ($filecount + $dircount == 0) { echo "<dd><i><empty folder></i></dd>\n"; }

 

}

 

printdir($rootdir);

 

?>

 

Link to comment
https://forums.phpfreaks.com/topic/214711-how-to-hide-appledouble-folder/
Share on other sites

For the certain file types part, instead of having

if (strtolower(substr($file, -4)) == ".avi")

Have something like

$allowed = array('.avi', '.jpg', '.gif'); // allowed file types

if (in_array(strtolower(substr($file, -4)), $allowed)) // the file extension must be in $allowed to be added

 

As for excluding certain folders, instead of

   if (@filetype($dir . "/" . $file) == "dir" AND $file != "." AND $file != "..")

Have something like

$badFolders = array('.AppDouble', 'badfolder2'); // excluded folders

   if (@filetype($dir . "/" . $file) == "dir" AND $file != "." AND $file != ".." AND in_array($file, $badFolders) == false)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.