开发者

PHP Filesize Error

I'm trying to write a PHP file mamanger, and when I changed the director from "." to "../uploads/", the filesize is giving me this error:

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

Line 83 is print(filesize($dirArray[$index])); (I know this isn't helpful alone, the line-numbers are just going to be off when I paste it in)

It's accurately listing the file name, but not the size for some reason.

This is the full script:

            // 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($in开发者_StackOverflowdex=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");


You are opening ../uploads/ folder for file scanning, but checking filesize in current working directory.

This should be helpful:

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

The same applies to your links, they need path correction to work.


You're reading the directory one level up and over from the current working directory (../uploads) then calling filesize() on the bare filename which is looking for the file in the current working directory.

Prepend ../uploads/ to $dirArray[$index] before calling filesize()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜