cyber0ne Posted October 18, 2006 Share Posted October 18, 2006 This is probably a simple one, but so far my searches have turned up no answer...I use "$fileHandle = opendir($directoryPath);" in a function to open a directory on my server (after which time, I will iterate through the files and put certain ones into an array). Normally, this works fine, but testing has found that it errors out when the $directoryPath contains a single quote (or potentially any of a short list of special characters, but so far this is the only one that's been found in testing).The error is:opendir([DIRECTORY_NAME]) [<a href='function.opendir'>function.opendir</a>]: failed to open dir: No such file or directory(of course, replace [DIRECTORY_NAME] with the actual directory name)One thing of note is that, in the error, it looks like it inserts the slash before the single quote automatically (and, of course, when I tried wrapping it in addslashes() it just doubled up on the slashes).Any ideas what I need to do here? I know the directory exists, that part's been triple-checked. It's found earlier in the script by using the same function to list all directories in the current directory. I can iterate up and down the entire tree, and the only directories that give me trouble are, without exception, the ones with a single-quote in the name. Link to comment Share on other sites More sharing options...
jhecht Posted October 18, 2006 Share Posted October 18, 2006 use stripslashes() instead of addslashes...addslashes escapes characters that would normally not be printed out to the browser. So addslashing a slash, means that the slash originally there would be echoed instead of just the punctation mark.And opendir is nice, but kinda long. use glob(); <?php$globText = "directoryName/*;foreach(glob($globText) as $value){echo $value."<br/>\n";}This will find every file under the directory "directoryName';?> Link to comment Share on other sites More sharing options...
cyber0ne Posted October 18, 2006 Author Share Posted October 18, 2006 Excellent, it's working now. And nice tip on glob, thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now