note 52326 added to function.dirname

From: Date: Wed, 27 Apr 2005 22:31:08 +0000
Subject: note 52326 added to function.dirname
Groups: php.notes 
Request: Send a blank email to php-notes+get-88664@lists.php.net to get a copy of this message
If you merely want to find out wether a certain file is located within or underneath a certain directory or not, e.g. for White List validation, the following function might be useful to you: <?php function in_dir ($file, $in_dir) { $dir = realpath ($file); $in_dir = realpath ($in_dir); if (!is_dir ($file)) { $dir = dirname ($file); } do { if ($dir === $in_dir) { $is_in_dir = TRUE; break; } } while ($dir !== ($dir = dirname ($dir))); return (bool) @$is_in_dir; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.dirname.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52326 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52326&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52326&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52326&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52326&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52326&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52326&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#88664) next »