Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Filesize Error

Tags:

php

html-table

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($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");
like image 867
JacobTheDev Avatar asked Dec 12 '25 06:12

JacobTheDev


1 Answers

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.

like image 151
dev-null-dweller Avatar answered Dec 14 '25 18:12

dev-null-dweller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!