Въпросче :)

morkov4o

Registered
Здравейте, здравейте!Имам едно въпросче. Та като чета файловете от дадена директория нали се показват и папките ... и искам така да го направя ,че когато няма разширение да се появява иконка папчица отпред:П Ако някой има идейка как мога да се убращам към " разширението " на файла плс да казва :)
 

vesku

Registered
ето виж кък съм го направил аз
пред всеки път до файл или папка слагаш $img
Код:
<?php
$filepat = "ПЪТЯ ДО ФАЙЛА";
$icons = strtolower(substr(strrchr($filepat,"."),1));
switch($icons)
{
case "txt":$img = "<img src=\"img/small/Txt.png\" border=\"0\">";
break;

case "bmp":case "jpg":case "jpeg":case "jpe":case "gif":case "emf":case "tif":case "png":$img = "<img src=\"img/small/Image.png\" border=\"0\">";
break;

case "ttf":$img = "<img src=\"img/small/Ttf.png\" border=\"0\">";
break;

case "ini":$img = "<img src=\"img/small/Ini.png\" border=\"0\">";
break;

case "bat":$img = "<img src=\"img/small/Script.png\" border=\"0\">";
break;		

case "dll":$img = "<img src=\"img/small/Binary.png\" border=\"0\">";
break;

case "sys":$img = "<img src=\"img/small/Binary.png\" border=\"0\">";
break;

case "com":$img = "<img src=\"img/small/Binary.png\" border=\"0\">";
break;

case "exe":$img = "<img src=\"img/small/Binary.png\" border=\"0\">";
break;

case "htm":$img = "<img src=\"img/small/Web.png\" border=\"0\">";
break;

case "shtm":$img = "<img src=\"img/small/Web.png\" border=\"0\">";
break;

case "html":$img = "<img src=\"img/small/Web.png\" border=\"0\">";
break;

case "shtml":$img = "<img src=\"img/small/Web.png\" border=\"0\">";
break;

case "php":$img = "<img src=\"img/small/Web.png\" border=\"0\">";
break;

case "doc":$img = "<img src=\"img/small/Word.png\" border=\"0\">";
break;

case "rtf":$img = "<img src=\"img/small/Word.png\" border=\"0\">";
break;

case "pdf":$img = "<img src=\"img/small/Pdf.png\" border=\"0\">";
break;

case "xls":$img = "<img src=\"img/small/Xls.png\" border=\"0\">";
break;

case "csv":$img = "<img src=\"img/small/Xls.png\" border=\"0\">";
break;

case "ppt":$img = "<img src=\"img/small/Ppt.png\" border=\"0\">";
break;

case "mdb":$img = "<img src=\"img/small/Mdb.png\" border=\"0\">";
break;

case "mda":$img = "<img src=\"img/small/Mdb.png\" border=\"0\">";
break;

case "zip":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "tar":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "gz":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "arj":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "lha":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "tgz":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "tar.gz":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "rar":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "jar":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "mp3":$img = "<img src=\"img/small/Sound.png\" border=\"0\">";
break;

case "wav":$img = "<img src=\"img/small/Sound.png\" border=\"0\">";
break;

case "mpe":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "mpg":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "mpeg":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "avi":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "mov":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "asf":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "asx":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "wmv":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "ram":$img = "<img src=\"img/small/Real.png\" border=\"0\">";
break;

case "ra":$img = "<img src=\"img/small/Real.png\" border=\"0\">";
break;

case "rm":$img = "<img src=\"img/small/Real.png\" border=\"0\">";
break;
default:$img = "<img src=\"img/small/Generic.png\" border=\"0\">";
}
if(is_dir($filepat))
{
$img = "<img src=\"img/small/papka.png\" border=\"0\">";
}
?>
 

morkov4o

Registered
Код:
<?php
$ime_papka="./";
$dir=opendir($ime_papka);

while(false!=($ime_file=readdir($dir)))
      {
          if(($ime_file!=".")and($ime_file!=".."))
             {
                 $spisyk[]="$ime_file";
                $link[]="http://boldly.freehostia.com/$ime_file";
             }
      }
closedir($dir)

?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="default.css" media="screen"/>
<title>Четене на директория</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
</head>
<body>
<u><?php echo($ime_papka); ?></u>
<hr>
<?php
$c = count($spisyk);
for($i=0; $i<$c; $i++)
{
  echo "<a href=\"$link[$i]\">$spisyk[$i]</a><br/>";    
}   
?>
</body></html>

По този начин ги изкарвам :) Не може да стане по твоя начин ...
 

vesku

Registered
ето ти кода :)
Код:
<?php
$ime_papka="./";
$dir=opendir($ime_papka);

while(false!=($ime_file=readdir($dir)))
      {
          if(($ime_file!=".")and($ime_file!=".."))
             {
                 $spisyk[]="$ime_file";
                $link[]="http://boldly.freehostia.com/$ime_file";
             }
      }
closedir($dir)

?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="default.css" media="screen"/>
<title>Четене на директория</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
</head>
<body>
<u><?php echo($ime_papka); ?></u>
<hr>
<?php
$c = count($spisyk);
for($i=0; $i<$c; $i++)
{
$icons = strtolower(substr(strrchr($spisyk[$i],"."),1));
switch($icons)
{
case "txt":$img = "<img src=\"img/small/Txt.png\" border=\"0\">";
break;

case "bmp":case "jpg":case "jpeg":case "jpe":case "gif":case "emf":case "tif":case "png":$img = "<img src=\"img/small/Image.png\" border=\"0\">";
break;

case "ttf":$img = "<img src=\"img/small/Ttf.png\" border=\"0\">";
break;

case "ini":$img = "<img src=\"img/small/Ini.png\" border=\"0\">";
break;

case "bat":$img = "<img src=\"img/small/Script.png\" border=\"0\">";
break;      

case "dll":$img = "<img src=\"img/small/Binary.png\" border=\"0\">";
break;

case "sys":$img = "<img src=\"img/small/Binary.png\" border=\"0\">";
break;

case "com":$img = "<img src=\"img/small/Binary.png\" border=\"0\">";
break;

case "exe":$img = "<img src=\"img/small/Binary.png\" border=\"0\">";
break;

case "htm":$img = "<img src=\"img/small/Web.png\" border=\"0\">";
break;

case "shtm":$img = "<img src=\"img/small/Web.png\" border=\"0\">";
break;

case "html":$img = "<img src=\"img/small/Web.png\" border=\"0\">";
break;

case "shtml":$img = "<img src=\"img/small/Web.png\" border=\"0\">";
break;

case "php":$img = "<img src=\"img/small/Web.png\" border=\"0\">";
break;

case "doc":$img = "<img src=\"img/small/Word.png\" border=\"0\">";
break;

case "rtf":$img = "<img src=\"img/small/Word.png\" border=\"0\">";
break;

case "pdf":$img = "<img src=\"img/small/Pdf.png\" border=\"0\">";
break;

case "xls":$img = "<img src=\"img/small/Xls.png\" border=\"0\">";
break;

case "csv":$img = "<img src=\"img/small/Xls.png\" border=\"0\">";
break;

case "ppt":$img = "<img src=\"img/small/Ppt.png\" border=\"0\">";
break;

case "mdb":$img = "<img src=\"img/small/Mdb.png\" border=\"0\">";
break;

case "mda":$img = "<img src=\"img/small/Mdb.png\" border=\"0\">";
break;

case "zip":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "tar":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "gz":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "arj":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "lha":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "tgz":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "tar.gz":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "rar":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "jar":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "mp3":$img = "<img src=\"img/small/Sound.png\" border=\"0\">";
break;

case "wav":$img = "<img src=\"img/small/Sound.png\" border=\"0\">";
break;

case "mpe":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "mpg":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "mpeg":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "avi":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "mov":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "asf":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "asx":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "wmv":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "ram":$img = "<img src=\"img/small/Real.png\" border=\"0\">";
break;

case "ra":$img = "<img src=\"img/small/Real.png\" border=\"0\">";
break;

case "rm":$img = "<img src=\"img/small/Real.png\" border=\"0\">";
break;
default:$img = "<img src=\"img/small/Generic.png\" border=\"0\">";
}
if(is_dir($spisyk[$i]))
{
$img = "<img src=\"img/small/papka.png\" border=\"0\">";
}
  echo "<a href=\"$link[$i]\">$img $spisyk[$i]</a><br/>";   
}   
?>
</body></html>
 

vesku

Registered
използвай това по добре малко ти преработих кода :)
Код:
<?php
if(isset($_GET["subdir"])) 
{
$subdir = $_GET["subdir"];
$ime_papka="$subdir";
}
else
{
$ime_papka="./";
}

$g=@opendir($ime_papka);
while ($fajl= @readdir( $g ) )
{


if(($ime_file!=".")and($ime_file!="..")) {
$spisyk[]=$fajl;
}
}

@closedir ($g);


$kolko=count ($spisyk);

?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="default.css" 

media="screen"/>
<title>Четене на директория</title>
<meta http-equiv="Content-Type" content="text/html; 

charset=windows-1251">
</head>
<body>
<u><?php echo($ime_papka); ?></u>
<hr>
<?php

for($i = 0; $i < $kolko; $i++)
{

$filepat=$ime_papka.'/'.$spisyk[$i];
$icons = strtolower(substr(strrchr($filepat,"."),1));
switch($icons)
{
case "txt":$img = "<img src=\"img/small/Txt.png\" border=\"0\">";
break;

case "bmp":case "jpg":case "jpeg":case "jpe":case "gif":case "emf":case 

"tif":case "png":$img = "<img src=\"img/small/Image.png\" 

border=\"0\">";
break;

case "ttf":$img = "<img src=\"img/small/Ttf.png\" border=\"0\">";
break;

case "ini":$img = "<img src=\"img/small/Ini.png\" border=\"0\">";
break;

case "bat":$img = "<img src=\"img/small/Script.png\" border=\"0\">";
break;     

case "dll":$img = "<img src=\"img/small/Binary.png\" border=\"0\">";
break;

case "sys":$img = "<img src=\"img/small/Binary.png\" border=\"0\">";
break;

case "com":$img = "<img src=\"img/small/Binary.png\" border=\"0\">";
break;

case "exe":$img = "<img src=\"img/small/Binary.png\" border=\"0\">";
break;

case "htm":$img = "<img src=\"img/small/Web.png\" border=\"0\">";
break;

case "shtm":$img = "<img src=\"img/small/Web.png\" border=\"0\">";
break;

case "html":$img = "<img src=\"img/small/Web.png\" border=\"0\">";
break;

case "shtml":$img = "<img src=\"img/small/Web.png\" border=\"0\">";
break;

case "php":$img = "<img src=\"img/small/Web.png\" border=\"0\">";
break;

case "doc":$img = "<img src=\"img/small/Word.png\" border=\"0\">";
break;

case "rtf":$img = "<img src=\"img/small/Word.png\" border=\"0\">";
break;

case "pdf":$img = "<img src=\"img/small/Pdf.png\" border=\"0\">";
break;

case "xls":$img = "<img src=\"img/small/Xls.png\" border=\"0\">";
break;

case "csv":$img = "<img src=\"img/small/Xls.png\" border=\"0\">";
break;

case "ppt":$img = "<img src=\"img/small/Ppt.png\" border=\"0\">";
break;

case "mdb":$img = "<img src=\"img/small/Mdb.png\" border=\"0\">";
break;

case "mda":$img = "<img src=\"img/small/Mdb.png\" border=\"0\">";
break;

case "zip":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "tar":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "gz":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "arj":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "lha":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "tgz":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "tar.gz":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "rar":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "jar":$img = "<img src=\"img/small/Comp.png\" border=\"0\">";
break;

case "mp3":$img = "<img src=\"img/small/Sound.png\" border=\"0\">";
break;

case "wav":$img = "<img src=\"img/small/Sound.png\" border=\"0\">";
break;

case "mpe":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "mpg":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "mpeg":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "avi":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "mov":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "asf":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "asx":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "wmv":$img = "<img src=\"img/small/Video.png\" border=\"0\">";
break;

case "ram":$img = "<img src=\"img/small/Real.png\" border=\"0\">";
break;

case "ra":$img = "<img src=\"img/small/Real.png\" border=\"0\">";
break;

case "rm":$img = "<img src=\"img/small/Real.png\" border=\"0\">";
break;
default:$img = "<img src=\"img/small/Generic.png\" border=\"0\">";
}
if(is_dir("$filepat"))
{
 $img = "<img src=\"img/small/papka.png\" border=\"0\">";
 echo "<a href=\"?subdir=$filepat\">$img $spisyk[$i]</a><br/>"; 
}
 if(is_file("$filepat"))
{
 echo "<a href=\"$filepat\">$img $spisyk[$i]</a><br/>";   
}
}   
?>
</body></html>
 

morkov4o

Registered
амм окс благодаря утре ще го тествам ,че сега не мога :)
 

Горе