Hi all,
I recently wrote a script to help deal with the disk quota for a user I gave an ftp account to for image storage. He has donated alot of money to our site so it was the least I could do to give him some storage space.
He ignores the emails notifying him of being over his quota, so I wrote this script to check his quota and if over by 105% then it will add a .htaccess file to prevent hotlinking, and chmod his folder to disallow directory listings. It works great as a crontab...but I cannot for the life of me figure out how to apply the chmod to subdirectories. My attempts at doing directory listings with the is_dir() function have failed. I can get a listing of directories only, and echo the list from within a web accessible folder...but when I put the code into my script in my vault folder (non-web accessible) and change the echo to a chmod...I get nothing. (I did change the opendir path too)
Here is the code I got to work to get the directories.
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle)))
{
if (is_dir($file) && $file != "." && $file != "..")
{
echo "$file\n";
}
}
}
That works fine by itself. So I figured I could replace the echo "$file\n"; with chmod ($path_to_dir . "/" . $file, 0701);
That did not work.
Here is an exerpt of my script, I tried inserting the above code inplace of the chmod line.
// If overlimit, write an .htaccess file to prevent hotlinks and chmod directory to 701
if ($p_space_taken >= "100")
{
$whattowrite = 'RewriteEngine on'."\n".'RewriteCond %{HTTP_REFERER} !^$'."\n".'RewriteRule .*\.(gif|GIF|jpg|JPG)$ ' . $path_to_image .' [R]';
if (file_exists($path_to_file))
{
unlink($path_to_file);
}
$fileHandler = fopen ($path_to_file, "w");
fwrite ($fileHandler, $whattowrite);
fclose ($fileHandler);
chmod ($path_to_dir, 0701);
}
Can anyone tell me what I might be doing wrong?