Hello,
What should be changed in the code below to make it compatible with PHP 8.2 version?
class treeview {
private $files;
private $folder;
function __construct( $path ) {
$files = array();
if( file_exists( $path)) {
if( $path[ strlen( $path ) - 1 ] == '/' )
$this->folder = $path;
else
$this->folder = $path . '/';
$this->dir = opendir( $path );
while(( $file = readdir( $this->dir ) ) != false )
$this->files[] = $file;
closedir( $this->dir );
}
}
function create_tree( ) {
if( count( $this->files ) > 2 ) { /* First 2 entries are . and .. -skip them */
natcasesort( $this->files );
$list = '<ul class="filetree" style="display: none;">';
// Group folders first
foreach( $this->files as $file ) {
if( file_exists( $this->folder . $file ) && $file != '.' && $file != '..' && is_dir( $this->folder . $file )) {
$list .= '<li class="folder collapsed"><a href="#" rel="' . htmlentities( $this->folder . $file ) . '/">' . htmlentities( $file ) . '</a></li>';
}
}
// Group all files
foreach( $this->files as $file ) {
if( file_exists( $this->folder . $file ) && $file != '.' && $file != '..' && !is_dir( $this->folder . $file )) {
$ext = preg_replace('/^.*\./', '', $file);
$list .= '<li class="file ext_' . $ext . '"><a href="#" rel="' . htmlentities( $this->folder . $file ) . '">' . htmlentities( $file ) . '</a></li>';
}
}
$list .= '</ul>';
return $list;
}
}
}
$path = urldecode( $_REQUEST['dir'] );
$tree = new treeview( $path );
echo $tree->create_tree();