what methods can i use to get a files size, i have tried using filesize()

but it keeps spitting out error if i try to use opendir on any directory other than the current dir?

so what other ways can i get a list of files in a dir and echo their sizes?

    I think it would be much better to tell us the error instead.

      sorry about the late reply:
      the errors:

      Warning: filesize() [function.filesize]: stat failed for ajaxpagefetcher.js in /home/.philadelphia/homer09001/files.dth-scripts.com/listfiles.php on line 12

      Warning: filesize() [function.filesize]: stat failed for Anim8or.exe in /home/.philadelphia/homer09001/files.dth-scripts.com/listfiles.php on line 12

      the code:

      
      <table border="1"><tr><td>FileName</td><td>File Size</td><td>File Type</td></tr>
      <?php
      $dirpath = "./files";
      
      $dh = opendir($dirpath);
      
      while (false !== ($file = readdir($dh))) {
      
      if (!is_dir("$dirpath/$file")) {
      
      $filesize = sprintf("%u", filesize($file));
      	if ($filesize < pow(2,10)){
      		$totalsize = "$filesize B";
      	}
      	if ($filesize >= pow(2,10) && $filesize < pow(2,20)) {
      		$totalsize = round($filesize / pow(2,10), 2)." KB";
      	}
      	if ($filesize >= pow(2,20) && $filesize < pow(2,30)) {
      		$totalsize = round($filesize / pow(2,20), 2)." MB";
      	}
      	if ($filesize > pow(2,30)) {
      		$totalsize = round($filesize / pow(2,30), 2)." GB";
      	}
      
      $path_parts = pathinfo($file);
      $ext = $path_parts['extension'];
      
      
      echo "<tr><td>$file</td><td>$totalsize</td><td>$ext<img src=\"fileicons/$ext.png\"></td></tr>";
              }}
      
      closedir($dh);
      ?>
      

        The directories in question will probably need to have at least read+execute permission for all users, and the files which you are inspecting will need at least read permission for all users (assuming PHP is being run as an Apache module, and thus the directories/files need to be readable by the Apache user account).

          Write a Reply...