Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getdir() problems in jqueryFileTree.php #273

Open
speters opened this issue Mar 11, 2021 · 3 comments · May be fixed by #299
Open

getdir() problems in jqueryFileTree.php #273

speters opened this issue Mar 11, 2021 · 3 comments · May be fixed by #299

Comments

@speters
Copy link

speters commented Mar 11, 2021

While trying out phpvirtualbox on a server running PHP 8.0.3, I ran into problems with the file selection dialog when trying to attach an ISO file.

image

This was due to the following error which showed up in the error logs:

PHP Fatal error:  Cannot redeclare getdir() in /usr/share/webapps/phpvirtualbox/endpoints/jqueryFileTree.php on line 224

getdir() seems to be a built-in function in PHP, so I wonder how this worked before.

The easiest fix is to rename getdir() function to something else.

Then another error showed up:

PHP Fatal error:  Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, null given in /usr/share/webapps/phpvirtualbox/endpoints/jqueryFileTree.php:256

For PHP versions >= 7.30 the fix is to use is_countable() instead of count().

With those fixes, directory selection is working now.

@linux-helmut
Copy link

linux-helmut commented Sep 19, 2021

Thanks... The fixes works!

Lines 224+ (count -> is_countable)
function getdir($dir, $dirsOnly=false, $recurse=array()) {
if(!$dir) $dir = DSEP;
$entries = getDirEntries($dir, $dirsOnly);
if(!is_countable($entries))
return array();
$dirents = array();
foreach($entries as $path => $type) {
if($type == 'folder' && is_countable($recurse) && (strcasecmp($recurse[0],vbox_basename($path)) == 0)) {
$entry = folder_entry($path, false, true);
$entry['children'] = getdir($dir.DSEP.array_shift($recurse), $dirsOnly, $recurse);
array_push($dirents, $entry);
} else {
if($type == 'folder') {
array_push($dirents, folder_entry($path));
} else {
$ext = strtolower(preg_replace('/^.*./', '', $file));
if(is_countable($allowed) && !$allowed['.'.$ext]) continue;
array_push($dirents, file_entry($path));
}
}
}
return $dirents;
}

@derekschrock
Copy link

derekschrock commented Feb 3, 2022

So this is just a work around. The function needs "global $allowed_ext", $allowed should be $allowed_exts and $file should be $path.

With the above your disabling the extensions filtering.

@derekschrock
Copy link

--- /root/jqueryFileTree.php    2022-02-03 00:17:43.668914000 -0500
+++ endpoints/jqueryFileTree.php        2022-02-03 00:17:04.731039000 -0500
@@ -223,6 +223,8 @@
  */
 function getdir($dir, $dirsOnly=false, $recurse=array()) {
 
+       global $allowed_exts;
+
        if(!$dir) $dir = DSEP;
 
        $entries = getDirEntries($dir, $dirsOnly);
@@ -251,9 +253,9 @@
                // Push file on to stack
                } else {
 
-                       $ext = strtolower(preg_replace('/^.*\./', '', $file));
+                       $ext = strtolower(preg_replace('/^.*\./', '', $path));
 
-                if(count($allowed) && !$allowed['.'.$ext]) continue;
+                if(count($allowed_exts) && !$allowed_exts['.'.$ext]) continue;
 
                 array_push($dirents, file_entry($path));
                }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants