Trouble listing files with blob()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
swsmoore
Forum Newbie
Posts: 7
Joined: Wed Feb 03, 2010 10:51 am

Trouble listing files with blob()

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Trouble listing files with blob()

Post by AbraCadaver »

Not sure why it's not picking up the text file, but try this:

Code: Select all

print_r(glob($dir."*"));
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
swsmoore
Forum Newbie
Posts: 7
Joined: Wed Feb 03, 2010 10:51 am

Re: Trouble listing files with blob()

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Trouble listing files with blob()

Post 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:

Code: Select all

glob(realpath($dir).'/*');
At a minimum do this to verify that ../ is really what you think it is:

Code: Select all

echo realpath($dir);
Other than that, maybe the web user doesn't have read permissions for that dir?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
swsmoore
Forum Newbie
Posts: 7
Joined: Wed Feb 03, 2010 10:51 am

Re: Trouble listing files with blob()

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Trouble listing files with blob()

Post by AbraCadaver »

What I said to do at a minimum is this:

Code: Select all

echo realpath($dir);
Or even better, change $dir to this:

Code: Select all

$dir = realpath('../pvse/');
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
swsmoore
Forum Newbie
Posts: 7
Joined: Wed Feb 03, 2010 10:51 am

Re: Trouble listing files with blob()

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Trouble listing files with blob()

Post 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."/*"));
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
swsmoore
Forum Newbie
Posts: 7
Joined: Wed Feb 03, 2010 10:51 am

Re: Trouble listing files with blob()

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Trouble listing files with blob()

Post 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');
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
swsmoore
Forum Newbie
Posts: 7
Joined: Wed Feb 03, 2010 10:51 am

Re: Trouble listing files with blob()

Post 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";
 

Code: Select all

 
Safe_mode:
1
Open_basedir:
 
 
-Susan
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Trouble listing files with blob()

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
swsmoore
Forum Newbie
Posts: 7
Joined: Wed Feb 03, 2010 10:51 am

Re: Trouble listing files with blob()

Post 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
Post Reply