2012-04-29 9 views
-1

PHP를 사용하여 파일 이름 옆에 파일 크기를 추가하려면 어떻게합니까 ??? PHP 파일 이름 및 파일 크기 출력

현재이 사용이로 출력

<?php 
# Configuration 
$show_path = 0; # Show local path. 
$show_dotdirs = 1; # Show '.' and '..'. 

$path = substr($_SERVER['SCRIPT_FILENAME'], 0, 
    strrpos($_SERVER['SCRIPT_FILENAME'], '/') + 1); 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
<link rel="stylesheet" type="text/css" href="style.css"/> 
</head> 

<body> 
<div id="menu"> 
    <div id="menualign"><a href="index.php"><img src="images/home.png" onmouseover="src='images/homed.png'" onmouseout="src='images/home.png'"/></a><img src="images/moviesa.png"/><a href="tvguide.php"><img src="images/tv.png" onmouseover="src='images/tvd.png'" onmouseout="src='images/tv.png'"/></a></div> 
</div> 
<div id="container"> 
    <div id="fleft"> 
    <table cellspacing="1"> 
     <tr> 
     <th><?php if ($show_path == 1) { echo $path; } else { echo 'Current Movies'; } ?></th> 
     </tr> 
     <tr> 
     <td align="left"><?php 
$dirs = array(); 
$files = array(); 

$dir = dir('../Movies/'); 
while ($entry = $dir->read()) { 
    if (($entry != '.') and (substr($entry, -4) != '.php')) { 
     if (is_dir($entry)) { 
      if (($entry != '..') or $show_dotdirs){ 
       $dirs[] = $entry; 
      } 
     } else { 
      $files[] = $entry; 
     } 
    } 
} 
$dir->close(); 

sort($dirs); 
foreach ($dirs as $dir) { 
    printf('<strong>&lt;</strong> <a href="%s">%s</a> <strong>&gt;</strong><br />' . "\n", $dir, $dir); 
} 

sort($files); 
foreach ($files as $file) { 
    printf('<hr />%s<br />' . "\n", $file, $file); 
} 
?></td> 
     </tr> 
    </table> 
    </div> 
    <div id="fright">TEST 
    </div> 
</div> 
</body> 
</html> 

: http://downunderpctech.com/output.png

나는 아마 동일한 코드를 사용하여 파일 크기

에 대한

을 섹션을 추가 할 수 있지만, 같은 파일 크기 정보를 수집 하시겠습니까 파일 이름이 새로 추가되었습니다.

저는 Filesize 출력에 대해별로 신경 쓰지 않지만, ou 만 선호합니다. tput을 KB는

감사합니다, 아담

답변

3

이를 추가 할 수 있습니다.

그리고 당신은 출력 this little function을 가진 사람이 읽을 수있는 크기 할 수 있습니다

function file_size($size) 
{ 
    $filesizename = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"); 
    return $size ? round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $filesizename[$i] : '0 Bytes'; 
} 

당신은 # Configuration 전에 함수를 정의하고 당신이 당신의 foreach 문에 전화 : 내가했던 있도록

echo file_size(filesize('../Movies/'.$file)); 
+0

고정 어떻게 내 funachion을 내 foreach에 사용합니까 ??? –

+0

내 대답을 업데이트했습니다 – j0k

+0

감사합니다, fianlly 내가 원하는 방식으로 작동했습니다. –

0

당신은 당신이 당신의 $file 변수에 함수 filesize를 사용해야합니다 당신의 foreach는

echo '<span>'.round(filesize ('../Movies/'.$file)/1024, 1).' Kb</span>'; 
+0

확인 이 : sort ($ files); 의 foreach ($ 파일로 $ 파일) { \t ($ tick1 = 0!) \t { \t \t 에코 "


"경우; \t} printf ('% s
'. "\ n", $ file, $ file); echo round (filesize ($ file)/1024, 1). ' KB
'; \t $ tick1 = $ tick1 + 1; } 그리고 모든 파일에서 모두 0KB를 받고 있습니다 ... –

+0

@AdamCoulson, – Adi