Page 1 of 1
Trouble listing files with blob()
Posted: Wed Feb 03, 2010 11:00 am
by swsmoore
Hello,
I am having trouble listing the files in a directory using blob(). It does not list anything even though there is a text file and three directories in the directory. I am running the program at the command line. It should be simple. What am I missing?
This is my code:
Code: Select all
#!/usr/bin/php -q
<?php
$dir = '../pvse/';
print "Directory - $dir\n";
if (is_dir($dir)) print "$dir is a directory\n";
else print "$dir is not a directory\n";
print_r(glob($dir."*.*"));
?>
This is my result:
Code: Select all
Directory - ../pvse/
../pvse/ is a directory
Thank you for any help you can provide.
Re: Trouble listing files with blob()
Posted: Wed Feb 03, 2010 11:16 am
by AbraCadaver
Not sure why it's not picking up the text file, but try this:
Re: Trouble listing files with blob()
Posted: Wed Feb 03, 2010 11:41 am
by swsmoore
Thanks for your reply. I tried what you suggested and got the same result.
But if blob will not list the directories too, it won't work for me.
What else can I use. I tried opendir() but my server is running in Safe Mode and won't allow it.
Re: Trouble listing files with blob()
Posted: Wed Feb 03, 2010 3:19 pm
by AbraCadaver
swsmoore wrote:Thanks for your reply. I tried what you suggested and got the same result.
But if blob will not list the directories too, it won't work for me.
What else can I use. I tried opendir() but my server is running in Safe Mode and won't allow it.
glob() will list directories. You can try:
At a minimum do this to verify that ../ is really what you think it is:
Other than that, maybe the web user doesn't have read permissions for that dir?
Re: Trouble listing files with blob()
Posted: Wed Feb 03, 2010 3:36 pm
by swsmoore
Thanks for the reply. Here are the permissions, owner and group of the file that I am trying to run (testprog.php) and of the directory that I am trying to list (pvse):
-rwxr-xr-x 1 root root 704 Feb 3 09:40 testprog.php
drwxr-xr-x 5 pvse psacln 4096 Jan 29 08:38 pvse
Do I have a permission problem?
I tried to run the code as you suggest, but I got the same result.
Code:
Code: Select all
#!/usr/bin/php -q
<?php
$dir = '../pvse/';
print "Directory - $dir\n";
if (is_dir($dir)) print "$dir is a directory\n";
else print "$dir is not a directory\n";
//print_r(glob($dir."*.*"));
print_r(glob(realpath($dir).'/*'));
?>
Result:
Code: Select all
Directory - ../pvse/
../pvse/ is a directory
Thanks for your help,
Susan
Re: Trouble listing files with blob()
Posted: Wed Feb 03, 2010 3:42 pm
by AbraCadaver
What I said to do at a minimum is this:
Or even better, change $dir to this:
Re: Trouble listing files with blob()
Posted: Wed Feb 03, 2010 4:22 pm
by swsmoore
OK. I put both of your suggestions in my script and here is what I got.
Here is my code:
Code: Select all
#!/usr/bin/php -q
<?php
$dir = '../pvse/';
echo realpath($dir)."\n";
print "Directory - $dir\n";
$dir = realpath('../pvse/');
if (is_dir($dir)) print "$dir is a directory\n";
else print "$dir is not a directory\n";
print_r(glob($dir."*"));
?>
Code: Select all
/var/www/vhosts/pvwatch.net/pvse
Directory - ../pvse/
/var/www/vhosts/pvwatch.net/pvse is a directory
Array
(
[0] => /var/www/vhosts/pvwatch.net/pvse
)
It gives me an array at the end but not the contents of the directory.
Thanks, Susan
Re: Trouble listing files with blob()
Posted: Wed Feb 03, 2010 4:30 pm
by AbraCadaver
Try this:
Code: Select all
$dir = realpath('../pvse/');
print "Directory - $dir\n";
if (is_dir($dir)) print "$dir is a directory\n";
else print "$dir is not a directory\n";
print_r(glob($dir."/*"));
Re: Trouble listing files with blob()
Posted: Wed Feb 03, 2010 4:57 pm
by swsmoore
Unfortunately, we are back to it not listing anything.
Code: Select all
$dir = realpath('../pvse/');
print "Directory - $dir\n";
if (is_dir($dir)) print "$dir is a directory\n";
else print "$dir is not a directory\n";
print_r(glob($dir."/*"));
Code: Select all
Directory - /var/www/vhosts/pvwatch.net/pvse
/var/www/vhosts/pvwatch.net/pvse is a directory
Thanks, Susan
Re: Trouble listing files with blob()
Posted: Wed Feb 03, 2010 5:48 pm
by AbraCadaver
I'm running low on ideas, but what do the following show:
Code: Select all
echo ini_get('safe_mode');
echo ini_get('open_basedir');
Re: Trouble listing files with blob()
Posted: Wed Feb 03, 2010 6:03 pm
by swsmoore
Here's what it does:
Code: Select all
echo "Safe_mode:\n";
echo ini_get('safe_mode')."\n";
echo "Open_basedir:\n";
echo ini_get('open_basedir')."\n";
-Susan
Re: Trouble listing files with blob()
Posted: Wed Feb 03, 2010 6:12 pm
by AbraCadaver
http://www.php.net/manual/en/ini.sect.safe-mode.php
My best guess is that you need to do the following as root:
Code: Select all
chown pvse:psacln testprog.php
chown -R pvse:psacln pvse
But I have little experience with safe mode.
Re: Trouble listing files with blob()
Posted: Thu Feb 04, 2010 1:00 pm
by swsmoore
You were right that it was a permission issue. I changed the ownership of the file that (your first suggestion) and it runs now. I had specifically picked to run it as root because I thought that root had permission to everything. Obviously not.
Thanks for your help,
Susan