2
Hello, I wonder how I can fix the following error: I have the code below, which gives the file size, consulting inside the host directory.
However, let’s say that the file has 800Mbs, then what happens is that it shows a value a little lower, as 792Mbs, not its exact value. I would like to know how to fix this error in the code below, I appreciate the help of all.
<?php
function tamanho_arquivo($arquivo) {
$tamanhoarquivo = filesize($arquivo);
/* Medidas */
$medidas = array('KB', 'MB', 'GB', 'TB');
/* Se for menor que 1KB arredonda para 1KB */
if($tamanhoarquivo < 999){
$tamanhoarquivo = 1000;
}
for ($i = 0; $tamanhoarquivo > 999; $i++){
$tamanhoarquivo /= 1024;
}
return round($tamanhoarquivo) . $medidas[$i - 1];
}
// tamanho do arquivo 800Mbs
echo tamanho_arquivo('filme.avi');
?>
Update 18/05/2015: I’m having a problem with this type code I have a dedicated and I used this function to show the file size and add the value in SQL in my dedicated worked only that in my friend’s dedicated keeps giving error in line 2 in $filesize = filesize($file);
Keeps giving the following warning Warning: filesize() [Function.filesize]: stat failed for .. /driver/rar/Document1.rar in /home/meusite/public_html/Adm/additor.php on line 49 line 49 in the case and where this function above starts and integrates to my item addition code.
Obs: line 49 and $filesize = filesize($file);
Could someone help me fix this?
The Bruno already helped me fix the code to put the exact size with everything I don’t understand why I’m giving this error.
How did you get the "real" file size information? It can be a simple difference between kB and kb usage.
– Fuad Saud
You’re making a mistake or a warning?
– bruno
Normally this error/warning may occur due to a lack of read/write permissions in the directory where the files are. You can check the permissions in the file/directory?
– bruno
in case and warning the code is not wrong.
– Striffer