Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP文件名和文件大小输出_Php_File_Directory_Filesize - Fatal编程技术网

PHP文件名和文件大小输出

PHP文件名和文件大小输出,php,file,directory,filesize,Php,File,Directory,Filesize,如何使用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); ?> <!DOCTYP

如何使用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>

无标题文件
试验
以下是哪些输出:

我想为文件大小添加一个部分

可能使用与文件名相同的代码,但收集文件大小信息,但在文件名旁边使用新的

我不太关心文件大小的输出,但更喜欢只输出KB


谢谢,Adam

您可以编写文件,然后使用filesize函数获取文件大小,并使用文件名中的大小重命名文件


您可以编写文件,然后使用filesize函数获取文件大小,并使用文件名中的大小重命名文件


您可以将其添加到您的foreach中

echo '<span>'.round(filesize ('../Movies/'.$file)/1024, 1).' Kb</span>';
echo'.round(文件大小('../Movies/'.$file)/1024,1)。'Kb';

您可以将其添加到您的foreach中

echo '<span>'.round(filesize ('../Movies/'.$file)/1024, 1).' Kb</span>';
echo'.round(文件大小('../Movies/'.$file)/1024,1)。'Kb';

您应该在
$file
变量上使用该函数

然后您可以输出一个人类可读的大小,包括:

#配置
之前定义函数,然后在foreach中调用它:

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

您应该在
$file
变量上使用该函数

然后您可以输出一个人类可读的大小,包括:

#配置
之前定义函数,然后在foreach中调用它:

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

好的,我已经这样做了:排序($files);foreach($files as$file){if($tick1!=0){echo“
”;}printf(“%s
”。“\n”,“$file,$file,$file”);echo round(filesize($file)/1024,1)。'KB
;$tick1=$tick1+1;}我从每个文件中得到的都是0KB…好的,所以我做了这个:排序($files);foreach($files as$file){if($tick1!=0){echo“
”;}printf(“%s
”。“\n”,“$file,$file,$file”);echo round(filesize($file)/1024,1)。'KB
;$tick1=$tick1+1;}我从每个文件得到的都是0KB…你能这样吗?谢谢:)那你可以吗?谢谢:)