Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #14168
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Subfolder in script |
| Date | 2014-08-12 14:27 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <lsd88n$q99$2@dont-email.me> (permalink) |
| References | <4a738670-21a1-4de4-9ed9-d9db7d19138c@googlegroups.com> |
On Tue, 12 Aug 2014 05:38:27 -0700, Danjel Jungersen wrote:
> $search_dir = '.';
> The .php file is stored on domain.tld/sub1
> The files are at domain.tld/sub1/sub2
> I want to change "$search_dir = '.';" to "$search_dir = '/sub2';"
opendir works on the filesystem, not on the url, you may need to specify
the absolute path relative to the filesystem root, or relative to the
current working directory, which might not be the directory the php file
is in.
See what value is returned by a call to getcwd() immediately before
calling opendir.
Also, when using opendir, it's always a good idea to check that the
result is non false before using it, and handle failures gracefully.
See also http://php.net/manual/en/function.opendir.php
Perhaps it would also be a good idea to wrap your opendir call in an
is_dir check and handle the case where is_dir is false as well.
"handle" means present a meaningful message to whoever is viewing the
script output, whether it is a web page or on a console, rather than just
ignoring the fault condition. Handling may also include some sort of
logging. See also the handy error_log() function.
http://uk1.php.net/manual/en/function.error-log.php
eg (adapted from the manual example for opendir, not actually tested):
if ( is_dir( $dir ) ) {
if ( $dh = opendir( $dir ) ) {
/* search through files */
}
closedir( $dh );
}
else {
/* opendir failed */
error_log( "opendir failed, cwd was '".getcwd()."' and \$dir was
'{$dir}'",1,"name@example.com" );
echo "<p>A server error occurred. The system maintainer has been
notified and will investigate this. Please try again later.</p>";
}
}
else {
/* is_dir returned false */
error_log( "is_dir returned false for '{$dir}', cwd was '".getcwd
()"'",1,"name@example.com" );
echo "<p>A server error occurred. The system maintainer has been
notified and will investigate this. Please try again later.</p>";
}
--
Denis McMahon, denismfmcmahon@gmail.com
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Subfolder in script Danjel Jungersen <danjel@jungersen.dk> - 2014-08-12 05:38 -0700 Re: Subfolder in script Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2014-08-12 10:08 -0400 Re: Subfolder in script Denis McMahon <denismfmcmahon@gmail.com> - 2014-08-12 14:27 +0000 Re: Subfolder in script Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-08-12 16:27 +0100
csiph-web