View Full Version : Easy question
AppleWilliam
March 1st, 2008, 12:35 PM
Hi I have no clue on PHP.
This is my code
<?php
$config["rootDir"] = "media/"; // Directory to start in.
$config["hideDir"] = ".,..,ievinc"; // List of directory names to be hidden from the system, system folders, etc. Use a , to seperate folders. NOT CASE SENSATIVE! (All folders that start with _ are hidden by default.)
$config["showExt"] = ".mp4,.mp3,.m4a,.mov,.m4v"; // Extensions of files that should be shown by system.
$config["template"] = "default"; // Template to use.
?>I don't just want it to display those file types. so if I delete the line, none of the files are displayed. How do I get it to display all extensions without typing them all in.
simplistik
March 1st, 2008, 12:46 PM
that means nothing to anyone here w/o seeing what the $config array does. this little snippet is part of a much larger piece of code that we'll need to see.
AppleWilliam
March 2nd, 2008, 11:43 AM
Above is one of the 2 files. This is the other one
<?php
session_start();
require_once "_admin/config.php";
// Do not edit anything further, unless you know what you are doing!
// Checks if .htaccess is locking directory listed in $config["rootDir"]
if(!is_file($config["rootDir"]."/.htaccess") && is_file(".htaccess")) {
//chmod($config["rootDir"],0755);
copy(".htaccess",$config["rootDir"]."/.htaccess");
}
// Checks if template is not default
if($_GET["template"]) {
$_SESSION["template"] = $_GET["template"];
}
else {
if(!$_SESSION["template"]) {
$_SESSION["template"] = $config["template"];
}
}
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"_templates/" . $_SESSION["template"] . "/default.css\"/>";
echo "<script type=\"text/javascript\" language=\"JavaScript\" src=\"_scripts/library.js\" />";
// Checks to see if $_GET["dir"] is set, if not sets default root.
if($_GET["dir"]) {
// Check for security problems!
$workingDir = $_GET["dir"];
}
else {
$workingDir = $config["rootDir"];
}
echo "<div id=\"root\">";
if(is_dir($workingDir)) {
if($dir = opendir($workingDir)) {
echo "<div class=\"style_header\"><span class=\"style_menu\"><form name=\"menuForm\" action=\"javascript:\"><input type=\"button\" value=\"Search\" onclick=\"librarySearch(prompt('Search:'));\"><select name=\"template\">";
// Reads through _template directory and lists options
echo "<option value=\"0\">Change Template?</option>";
if($tempDir = opendir("_templates")) {
while(($file = readdir($tempDir)) !== false) {
if(is_dir("_templates/$file") && !preg_match("/$file/i",".,..")) {
echo "<option value=\"$file\">$file</option>";
}
}
}
echo "</select><input type=\"button\" value=\">>\" onclick=\"window.location='?dir=" . urlencode($workingDir) . "&template='+document.menuForm.template.options[document.menuForm.template.selectedIndex].value;\"></form></span><b>Ipod Media *** Search ---></b></div>";
$directories = Array();
$directories["_home"] = "<a href=\"?\"><div class=\"style_dir style_item style_system_item\"><img src=\"_templates/" . $_SESSION["template"] . "/img/home.png\">Home</div></a>";
$directories["_divider1"] = "<div class=\"style_divider\"></div>";
$files = Array();
while(($file = readdir($dir)) !== false) {
$fileURL = urlencode("$workingDir/$file");
$fileLOC = "$workingDir/$file";
if(is_dir("$workingDir/$file")) {
// If $file is a Directory do this...
if(!preg_match("/$file/i",$config["hideDir"]) && substr($file,0,1) != "_") {
$icon = "<img src=\"_templates/" . $_SESSION["template"] . "/img/dir.png\">";
if(is_file("$fileLOC/icon")) {
$icon = "<img src=\"$fileLOC/icon\">";
}
$directories[$file] = "<a id=\"q_$file\" href=\"?dir=$fileURL\"><div class=\"style_dir style_item\">$icon$file</div></a>";
}
}
else {
// If $file is a File do this...
$fileExt = substr($file,strrpos($file,"."));
$iconURL = "_templates/" . $_SESSION["template"] . "/img/ext.default.png";
//Checks to see if icon for file type exists.
if(is_file("_templates/" . $_SESSION["template"] . "/img/ext." . substr($fileExt,1) . ".png")) {
$iconURL = "_templates/" . $_SESSION["template"] . "/img/ext." . substr($fileExt,1) . ".png";
}
if($config["showExt"]) {
if(preg_match("/,$fileExt,|^$fileExt,|,$fileExt$|^$fileExt$/i",$config["showExt"])) {
$files[$file] = "<a id=\"q_$file\" href=\"play.php?file=$fileURL\" target=\"_blank\"><div class=\"style_item style_file_ext_" . substr($fileExt,1) . "\"><img src=\"$iconURL\" alt=\"$fileExt\">" . substr($file,0,strrpos($file,".")) . "</div></a>";
}
}
}
}
// Settings not used in this build!
//$directories["_divider2"] = "<div class=\"style_divider\"></div>";
//$directories["_settings"] = "<a href=\"_admin/\"><div class=\"style_dir style_item style_system_item\"><img src=\"_templates/" . $_SESSION["template"] . "/img/dir.png\">Settings</div></a>";
// Writes out all the directories, then writes out all the files.
echo "<div id=\"directories\">";
foreach($directories as $value) {
echo "$value";
}
echo "</div><div id=\"files\">";
foreach($files as $value) {
echo "$value";
}
echo "</div>";
}
}
else {
echo "Not a valid Directory! [" . $_GET["dir"] . "]";
}
echo "</div>";
?>
simplistik
March 2nd, 2008, 12:28 PM
need to provide config.php
prstudio
March 3rd, 2008, 11:08 AM
Or you should be able to change this:
if($config["showExt"]) {
if(preg_match("/,$fileExt,|^$fileExt,|,$fileExt$|^$fileExt$/i",$config["showExt"])) {
$files[$file] = "<a id=\"q_$file\" href=\"play.php?file=$fileURL\" target=\"_blank\"><div class=\"style_item style_file_ext_" . substr($fileExt,1) . "\"><img src=\"$iconURL\" alt=\"$fileExt\">" . substr($file,0,strrpos($file,".")) . "</div></a>";
}
}
to this:
$files[$file] = "<a id=\"q_$file\" href=\"play.php?file=$fileURL\" target=\"_blank\"><div class=\"style_item style_file_ext_" . substr($fileExt,1) . "\"><img src=\"$iconURL\" alt=\"$fileExt\">" . substr($file,0,strrpos($file,".")) . "</div></a>";
Now this alters functionality of the " $config["showExt"] " rendering it basically useless.
And should show all files like you desire.
If you provide the config.php like simplistik mentioned, then you might be able to include a certain value in $config["showExt"] that will automatically show all files.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.