Capture size and extension of a file and report via HTML

1

I have a listing of files on a page that I'm developing. The HTML looks like this:

<li class="downloadsCont">
<div class="grid_365 f-left">
    <div class="downloadsContImg f-left">
        <img src="fotoSYS&w=290" alt="" />
    </div>
</div>
<div class="grid_540 f-left">
    <div class="downloadsTit margin-top-35">
            <h2>tituloSYS</h2>
<span>descricaoSYS</span>
<i>Tamanho: 348Kb</i>
<i>Tipo: .PDF</i>

    </div>
</div>
<div class="downloadsBt margin-top-15">
    <div class="downloadsBtText">Download</div>
</div>

What I want, is that where it is informed <i> it shows the size of the file and also the format. Does anyone have any idea how I can do this?

This file will be managed by our own managed.

    
asked by anonymous 30.09.2014 / 15:08

1 answer

3

Come on ... You'll be able to do both using PHP ...

File extension

PHP: public string SplFileInfo::getExtension ( void )

Example:

$info = new SplFileInfo('foo.txt');
var_dump($info->getExtension());

You will allocate var_dump to any variable, hence you call it and it will give the file extension to you.

About File Size

For the file size, use: int filesize ( string $filename ) . Example:

$filename = 'arquivo.txt';
echo $filename . ': ' . filesize($filename) . ' bytes';

In doubt, you can turn to doc. PHP official: filesize and SplFileInfo

Code with PHP

    

<div class="grid_365 f-left">
    <div class="downloadsContImg f-left"><img alt="" src=
    "fotoSYS&w=290"></div>
</div>

<div class="grid_540 f-left">
    <div class="downloadsTit margin-top-35">
        <h2>tituloSYS</h2><span>descricaoSYS</span> 
        <i>Tamanho: <?php echo $fileSize ?></i>
        <i>Tipo: <?php echo $fileType ?></i>
    </div>
</div>

<div class="downloadsBt margin-top-15">
    <div class="downloadsBtText">
        Download
    </div>
</div>

    
30.09.2014 / 15:15