PDA

View Full Version : سوال: مشکل نمایش محتوای یک دایرکتوری



help20
پنج شنبه 02 خرداد 1392, 02:41 صبح
سلام دوستان خسته نباشید
این کد رو میشه بگین چرا خطا میده؟!!



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>دایرکتوری مورد نظر</title>

<style>
*{
padding:0;
margin:0;
}
html,body {
color:#333;
font-family: "Tahoma";
font-size:11px;
direction:rtl;
text-shadow:1px 1px 1px #cacaca;
-webkit-text-shadow:1px 1px 1px #cacaca;
-moz-text-shadow:1px 1px 1px #cacaca;
}
a{
padding: 2px 0 0 24px;
color:#3780b3;
text-decoration:none;
}
a:hover{
color:#000;
}
#container{
margin:0 auto;
width:800px;
margin-top:20px;
padding-top:10px;
border:1px solid #EEE;
border-radius:10px;
-moz-border-radius:10px;
}
.head{
background-color:#6ca607;
color:#FFF;
padding:7px 0 5px 10px;
font-size:11px;
letter-spacing:1px;
font-family: Tahoma;
}
.head:hover{background-color:#FE4902;}
.head span{font-size:9px; letter-spacing:0;}
td{
background-color:#F3F3F3;
padding:6px;
}
td:hover{background-color:#EFEFEF;}
h1{
font-size:12px;
padding:0 0 10px 10px;
}
</style>

</head>

<body>


<?php
$myDirectory = opendir("image");

while($entryName = readdir($myDirectory)) {
$dirArray[] = $entryName;
}

function frmtindex ($filename)
{
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}

closedir($myDirectory);

$indexCount = count($dirArray);

sort($dirArray);

print("<h1>محتوای دایرکتوری</h1>");
print("<table width='100%' cellspacing='10'>
<tr>
<td width='70%' class='head'>نام فایل</td>
<td width='10%' class='head'>فرمت</td>
<td width='15%' class='head'>اندازه</td>
<td width='15%' class='head'>تاریخ</td>
<td width='5%' class='head'>حذف</td></tr>\n");

for($index=0; $index < $indexCount; $index++) {
if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files
print("<tr><td><a target='_blank' href='$dirArray[$index]'>$dirArray[$index]</a></td>");
print("<td>");
print(frmtindex($dirArray[$index]));
print("</td>");
print("<td>");
print(round(filesize($dirArray[$index]) / 1024, 2));
print("</td>");
print("<td>");
print(date("D j M G:i:s", filemtime($dirArray[$index])));
print("</td>");
print("<td>
<form action='directory.php' method='post'>
<input style='display:none' type='text' value='$dirArray[$index]' name='filename'></br>
<input type='Submit' style='font-size:11px;font-family:tahoma;' name='delfile' value='حذف'>
</form>
</td>");
print("</tr>\n");
}
}
print("</table>\n");
?>


</body>

</html>

imanitc
پنج شنبه 02 خرداد 1392, 11:37 صبح
<html>
<body>

<?php
$dir = "."; // current directory (from file system point of view)

// figure out link path for files
$php_self = $_SERVER['PHP_SELF'];
$web_path = substr($php_self, 0, strrpos($php_self, "/")+1);


// Open the directory, and proceed to read its contents
if (is_dir($dir))
{
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{

if ($file == "." || $file == ".." || $file == "index.php" || $file == "Thumbs.db")
{
continue;
}

$file_array[] = $file;
}
closedir($dh);
}
}

sort($file_array);
?>


<h2><?php echo $web_path?></h2>
<ul>

<?php
foreach ($file_array AS $file)
{
?>
<li><a href='<?php echo $web_path?><?php echo rawurlencode($file)?>'><?php echo $file?></a>
<?php
}
?>

</ul>

</body>
</html>

help20
پنج شنبه 02 خرداد 1392, 12:10 عصر
دوست عزیز مرسی

این خط درسته ؟

print(frmtindex($dirArray[$index]));