i currently have a script which i want to modify to use the strrchr function rather the explode...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>FileBrowser</title>
<style>
body {
font-family:Arial, Helvetica, sans-serif;
font-size:12px
}
.current_dir {
font-size:18px;
font-weight:bold
}
</style>
</head>
<body>
<center>
<div style="text-align:left; width:940px">
<div class="current_dir">
<?php
error_reporting(E_ALL);
$dir_name = explode("/", dirname(__FILE__));
if(isset($_GET['dir']) and file_exists($_GET['dir'])){
echo "./".$dir_name[count($dir_name)-1]."/".trim($_GET['dir'], "./")."/";
} else {
echo "./".$dir_name[count($dir_name)-1]."/";
}
?>
</div><br/>
<table border="1" cellspacing="0" cellpadding="2">
<tr><td width="40"><b>Type</b></td><td width="600"><b>Filename</b></td><td width="70"><b>Size</b></td><td width="100"><b>Date Modified</b></td><td width="50"><b>Permissions</b></td>
</tr>
<?php
// Settings //////////////
/* Only allow users to view the same directory this file is placed in. false: let users browse all directories */
$current_dir_only = false;
/* Hide certain file types. Example: $hide_files = array("php", "txt"); */
$hide_files = array("php");
//////////////////////////
if(isset($_GET['dir'])){
$dir = $_GET['dir'];
} else {
$dir = ".";
}
if($current_dir_only == true){
$dir = ".";
}
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if($file == ".." and isset($_GET['dir'])){
$back = explode("/", $_GET['dir']);
unset($back[count($back)-1]);
$link = implode("/", $back);
} else {
$link = $file;
$back = array();
}
// if dir exists, make the link to it
if(is_dir("./$dir/$link/")){
$link = "$dir/$link";
}
// .. link problem
if(count($back)-1 == 0 and is_dir("./$dir/$link/")){
$link = "";
} else {
$link = "dir=$link";
}
// as not to make ../dir/../beginning
if($file == ".." and count($back) == 1){
$link = "";
}
// link to file or dir
if(is_file(trim("$dir/$file", "dir="))){
$link = trim("$dir/$file", "dir=");
} else {
$link = "?{$link}";
}
if(is_file(trim("$dir/$file", "dir="))){
$filesize = round(filesize($link)/1000000, 2);
$filesize .= "MB";
$modified = date("j/m/y h:i", filemtime($link));
$type = explode(".", $file);
$type = $type[count($file)];
$perm = substr(sprintf('%o', fileperms($link)), -4);
} else {
$dirname = trim("$dir/$file", "dir=");
$filesize = " ";
$modified = " ";
$type = "Dir";
if(file_exists($dirname)){
$perm = substr(sprintf('%o', fileperms("$dirname")), -4);
}
}
if($link == "?dir=./"){
$link = "?dir=../";
}
if($current_dir_only == true and $type == "Dir"){
$show_dir = 0;
} else {
$show_dir = 1;
}
if(!isset($_GET['dir']) and $file == ".."){
$no_go_back = true;
} else {
$no_go_back = false;
}
if($file != "."){
if($no_go_back == false){
if($show_dir != 0){
if(!in_array($type, $hide_files)){
echo "<tr><td>$type</td><td><a href=\"$link\">$file</a></td><td>$filesize</td><td>$modified</td><td>$perm</td></tr>\n";
}
}
}
}
}
closedir($dh);
}
}
?>
</table>
</div>
<br />
Within the section below,
$type = explode(".", $file);
$type = $type[count($file)];
I would like to change it from explore to strrchr to allow me to get the extenstion after the last dot, as which this code at the mo it doesnt work it theres more then one dot in the file name...
Any help would be great...