【问题标题】:PHP Filesize ErrorPHP 文件大小错误
【发布时间】:2018-07-14 18:27:02
【问题描述】:

我正在尝试编写一个 PHP 文件管理器,当我将导演从“.”更改为到“../uploads/”,文件大小给了我这个错误:

警告:filesize() [function.filesize]: stat failed for zipped-file.zip in /f5/jb-cms-testing/public/edit/files.php on line 83

第 83 行是 print(filesize($dirArray[$index]));(我知道单独这样做是没有用的,当我将它粘贴进去时,行号会消失)

它准确地列出了文件名,但由于某种原因没有列出大小。

这是完整的脚本:

            // open this directory 
            $myDirectory = opendir("../uploads/");

            // get each entry
            while($entryName = readdir($myDirectory)) {
                $dirArray[] = $entryName;
            }

            // close directory
            closedir($myDirectory);

            //  count elements in array
            $indexCount = count($dirArray);
            Print ("$indexCount files<br>\n");

            // sort 'em
            sort($dirArray);

            // print 'em
            print("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks>\n");
            print("<TR><TH>Filename</TH><th>Filetype</th><th>Filesize</th></TR>\n");
            // loop through the array of files and print them all
            for($index=0; $index < $indexCount; $index++) {
                    if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files
                    print("<TR><TD><a href=\"$dirArray[$index]\">$dirArray[$index]</a></td>");
                    print("<td>");
                    print(filesize($dirArray[$index]));
                    print("</td>");
                    print("</TR>\n");
                }
            }
            print("</TABLE>\n");

【问题讨论】:

  • 表示$dirArray[$index]中的文件不存在。当文件大小调用失败时,变量包含什么?
  • 如果文件确实存在,是否>2GB?
  • 1.我不知道,这是来自一个教程,我对 PHP 2 很陌生。不,现在每个文件大约 100kb,我不认为它们会变得那么大。

标签: php html-table


【解决方案1】:

您正在打开../uploads/ 文件夹进行文件扫描,但正在检查当前工作目录中的文件大小。

这应该会有所帮助:

print(filesize( '../uploads/' . $dirArray[$index]));

这同样适用于您的链接,它们需要路径更正才能工作。

【讨论】:

    【解决方案2】:

    您正在从当前工作目录 (../uploads) 读取上一级目录,然后在正在查找当前工作目录中的文件的裸文件名上调用 filesize()

    在调用filesize()之前将../uploads/添加到$dirArray[$index]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-22
      • 1970-01-01
      • 2012-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多