Capture file size and extension and inform via HTML

Asked

Viewed 34 times

1

I have a list of files on a page I’m developing. The HTML is 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 the <i> it shows the file size and also the format. Does anyone have any idea how I can do this?

This file will be managed by our own managed.

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 the var_dump in any variable, then you call it and it will give the file extension to you.

The size of the File

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

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

When in doubt, you can use the official doc. of PHP: 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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.