I have put together a script that will show the file size of a linked file (e.g. <a href="myfile.pdf" title="30.7 Kb">My File</a>).
I have got it working to show the link and the file size, but I need some help to hide the file's location as it's working on an absolute reference which shows the full path to the file (see below).
Here's the script:
Code: Select all
<?php
$file_type = array( 'K', 'M', 'G' );
$size = filesize ( $f );
for ( $t = 0; $size > 1024; $t++ )
{
$size /= 1024;
$file_size = round ( $size, 1 ) . ' ' . $file_type[ $t ] . 'B';
}
echo "<a href=\"$f\" class=\"pdf\" title=\"$file_size\">$f</a>";
?>Code: Select all
<?php $f = "/home/fhlinux13/l/mydomain.co.uk/user/htdocs/publications/myfile.pdf";?>Can anyone help to show me how to hide the absolute reference to the file? It is showing on the processed page as follows:
Code: Select all
<a href="/home/fhlinux13/l/mydomain.co.uk/user/htdocs/publications/myfile.pdf" title="823.9 KB">/home/fhlinux13/l/mydomain.co.uk/user/htdocs/publications/myfile.pdf</a>
Many thanks,
Mark