1

After i upload some files to my server, and save them in sql, i list them on my site.

while($a = mysqli_fetch_assoc($get_files))
        {
            $path_parts = pathinfo($a['fajl_file']);
            $extension = $path_parts['extension'];

            $path = $host.'/documents/'.$a['fajl_file'];

            echo '<tr>
                <td>'.html($a['fajl_nev']).'</td>
                <td>'.date_substr($a['fajl_datetime']).'</td>
                <td>'.$extension.'</td>
                <td>'.filesize($path).'</td>
                <td class="table_text_center">
                    <a class="table_delete_link delete_data" id="" href="#"><i class="fa fa-download"></i></a>
                </td>
            </tr>';
        }

Where i am listing the files, i want to display not just the name or upload date, i want the file size also.

With this code, i get this error:

Warning: filesize(): stat failed for

When i check the website source, the path i gived, its correct. The files are in the documents folder on the server.

B. Desai
  • 16,414
  • 5
  • 26
  • 47
Dave599
  • 19
  • 5

2 Answers2

0

Use the filepath for the filesize() function.

example filepath:

/var/www/myfile.txt

or on Windows

C:\xampp\htdocs\myfile.txt
Frank B
  • 3,667
  • 1
  • 16
  • 22
0

Your issue is that you are passing an absolute URL to the filesize() function when it needs a relative local file link (Qualifier: Some URLs are valid in PHP5+).

   $path = $host.'/documents/'.$a['fajl_file'];
   /*** 
   /*  http://www.someweb.site/documents/somefile.pdf
   /***/
   echo '<td>'.filesize($path).'</td>';

The above is passing to output filesize("http://www.someweb.site/documents/somefile.pdf") which is not what you want, you need to translate the document path to the local file version

You can do this using $_SERVER['DOCUMENT_ROOT']:

   $path = $host.'/documents/'.$a['fajl_file'];
   $localPath = $_SERVER['DOCUMENT_ROOT'] . '/documents/'.$a['fajl_file'];
   /*** 
   /*  /home/users/webaccount/www/documents/somefile.pdf
   /***/
   echo '<td>'.filesize($localPath).'</td>';

This should then output the data requested.

Martin
  • 22,212
  • 11
  • 70
  • 132