Hoang_philong
10-08-09, 11:36 AM
<?php
$root_domain = "http://".$_SERVER['HTTP_HOST'];
$dir = @opendir("./");
while ( FALSE !== ($file = readdir($dir)) )
{
if (is_dir($file))
{
echo "<tr><td><a href='{$root_domain}/{$file}'>{$file}</a><br></td></tr>";
}
else
{
$files[] = "-- <a href='{$root_domain}/{$file}'>{$file}</a><br></td></tr>";
}
}
foreach ( $files as $value )
{
echo $value;
}
@closedir($dir);
?>
Hướng dẫn:
Đoạn dưới lấy domain chính - nơi chứa file:
$root_domain = "http://".$_SERVER['HTTP_HOST'];
Mở thư mục / và nạp vào biến $dir
$dir = @opendir("./");
Đọc nội dung của biến $dir
$file = readdir($dir)
Kiểm tra coi có cái gì trong $dir hôn, nếu có thì nạp dữ liệu lia lịa
while ( FALSE !== ($file = readdir($dir)) )
{
[.......]
}
Kiểm tra xem dữ liệu là folder hay file, nếu là folder thì... còn nếu không thì...
if (is_dir($file))
{
[.......]
}
else
{
[.......]
}
Để phân biệt folder với file, đặt biến $files chứa thông tin của các file, xem tiếp bên dưới để biết tại sao...
$files[] = "-- <a href='{$root_domain}/{$file}'>{$file}</a><br></td></tr>";
Truy xuất dữ liệu của biến $files :)
foreach ( $files as $value )
{
echo $value;
}
Mở nắp hộp, xem xong thì phải biết đóng lại chứ !!!
@closedir($dir);
$root_domain = "http://".$_SERVER['HTTP_HOST'];
$dir = @opendir("./");
while ( FALSE !== ($file = readdir($dir)) )
{
if (is_dir($file))
{
echo "<tr><td><a href='{$root_domain}/{$file}'>{$file}</a><br></td></tr>";
}
else
{
$files[] = "-- <a href='{$root_domain}/{$file}'>{$file}</a><br></td></tr>";
}
}
foreach ( $files as $value )
{
echo $value;
}
@closedir($dir);
?>
Hướng dẫn:
Đoạn dưới lấy domain chính - nơi chứa file:
$root_domain = "http://".$_SERVER['HTTP_HOST'];
Mở thư mục / và nạp vào biến $dir
$dir = @opendir("./");
Đọc nội dung của biến $dir
$file = readdir($dir)
Kiểm tra coi có cái gì trong $dir hôn, nếu có thì nạp dữ liệu lia lịa
while ( FALSE !== ($file = readdir($dir)) )
{
[.......]
}
Kiểm tra xem dữ liệu là folder hay file, nếu là folder thì... còn nếu không thì...
if (is_dir($file))
{
[.......]
}
else
{
[.......]
}
Để phân biệt folder với file, đặt biến $files chứa thông tin của các file, xem tiếp bên dưới để biết tại sao...
$files[] = "-- <a href='{$root_domain}/{$file}'>{$file}</a><br></td></tr>";
Truy xuất dữ liệu của biến $files :)
foreach ( $files as $value )
{
echo $value;
}
Mở nắp hộp, xem xong thì phải biết đóng lại chứ !!!
@closedir($dir);