nayen
January 21, 2013, 7:52pm
1
Hi,
I have the following code in my application and it is not working on a certain VPS server and I have no idea why.
Server: Linux - PHP Version 5.3.16
<?php
define('PROJECTS_DIR', '../projects/');
// Gets project names from the projects folder.
function projects() {
$projects = glob(PROJECTS_DIR.'*', GLOB_ONLYDIR);
for ($i=0; $i<count($projects); $i++) {
$projects[$i] = basename($projects[$i]);
}
return $projects;
}
$projects = projects();
if (empty($projects)) {
echo 'No projects found.';
}
?>
The above code works fine on all other servers I tested but not on this one. What could be the reason? What should I check in phpinfo() or php.ini?
Thanks for any ideas.
What do you mean by “not working” ? Do you get an error? An empty screen? The ‘no projects found’ message while there are projects?
Maybe the PHP version on that server is < 4.3.0 ?
And you might want to do a var_dump($projects) in the function to check the value.
nayen
January 21, 2013, 9:32pm
3
guido2004:
What do you mean by “not working” ? Do you get an error? An empty screen? The ‘no projects found’ message while there are projects?
Maybe the PHP version on that server is < 4.3.0 ?
And you might want to do a var_dump($projects) in the function to check the value.
No errors, no output. PHP 5.3.16.
I tried var_dump($projects), it gave
array(1) { [0]=> string(0) “” }
So, the problem is probably with the function, maybe glob() doesn’t work with some setting. No idea…
This is part of a function I use to create a drop-down menu that provides a list of directory names in $logs_dir. It works on several servers including windows/IIS7
It might throw some light on your problem:
foreach(glob($logs_dir.'/*', GLOB_ONLYDIR) as $dir){
$dir = basename($dir);
if(stripos($dir,".") != FALSE){
$html .= '<option value='.$dir. '>' .$dir. '</option>';
}
}
nayen
January 22, 2013, 9:38am
5
The issue seems to be that glob() function is not working on that server. No idea if it is disabled or if it can be disabled somehow. If you have any ideas, please share with me. Thanks.
What PHP version is installed on that server? Must be 4.3.x or higher for glob() to work
nayen
January 22, 2013, 9:55am
7
PHP 5.3.16 as I mentioned two times previously. I also checked php.ini and “disable_functions” is empty. I don’t understand why in the world would glob not work on that one server while it is working on like a thousand other different servers.
Standard ‘omg it doesnt work, but its not a WPSE’ debugging. Echo all the things!
<?php
define('PROJECTS_DIR', '../projects/');
echo "ProjDir: ". PROJECTS_DIR."<br />";
// Gets project names from the projects folder.
function projects() {
$projects = glob(PROJECTS_DIR.'*', GLOB_ONLYDIR);
echo "FDebug1: ".print_r($projects,true)."<br/>";
for ($i=0; $i<count($projects); $i++) {
$projects[$i] = basename($projects[$i]);
}
echo "FDebug2: ".print_r($projects,true)."<br/>";
return $projects;
}
$projects = projects();
echo "EDebug1: ".print_r($projects,true)."<br/>";
if (empty($projects)) {
echo 'No projects found.';
}
?>
@StarLion ; a complicating factor is this (from the php manual ):
Note:
On some systems it is impossible to distinguish between empty match and an error.
So the empty array the OP gets could mean that there are no projects, or that there was an error.