PHP Check if any file is under certain directory |
For a list of all requirements and guidelines pertaining to posting a new Help topic, please click here.
This Month's Contests | Staff Member of the Month | Hosts Looking for Hostees | Hostees looking for Hosts | BigBookofResources
Submission Guidelines
PHP Check if any file is under certain directory |
Sep 27 2010, 10:07 PM
Post
#1
|
|
![]() Mel Blanc was allergic to carrots. ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 6,371 Joined: Aug 2008 Member No: 676,291 |
Thinking it'd a be a lot more efficient, I was wondering: how do you check to see if a file is under a certain directory? Basically, it would be something similar to a wildcard or something.
I'm pretty familiar with checking the URL's file name (in the most basic method): CODE <?php $uri = $_SERVER['SCRIPT_NAME']; if ($uri == '/path/to/file.php') echo 'Woo.'; else echo 'Aw.'; ?> Now, what I'm imagining, when it comes to checking for any file under a directory, is this: CODE <?php $uri = $_SERVER['SCRIPT_NAME']; $name = *WILDCARD SORT OF SHIT HERE*; if ($uri == '/path/to/' . $name . '.php') echo 'Woo.'; else echo 'Aw.'; ?> Any ideas would be awesomely appreciated. Yeah, awesomely is a word. |
|
|
|
Mikeplyts PHP Check if any file is under certain directory Sep 27 2010, 10:07 PM
ahmad This should work.
CODE<?php
// file_exists... Sep 28 2010, 12:14 PM
Mikeplyts Ergh, no. That's not really what I was looking... Sep 28 2010, 04:07 PM
mipadi Use glob:
CODEif (in_array($uri, glo... Sep 28 2010, 04:53 PM
Mikeplyts Hrm, that doesn't seem to work.
Oh, what if I... Sep 30 2010, 10:40 PM
mipadi Use ** to match directories and subdirectories. Oct 1 2010, 09:11 AM![]() ![]() |