How to get size of an image in KB? Can this be made with Javascript or PHP?
Printable View
How to get size of an image in KB? Can this be made with Javascript or PHP?
This JS will only work in IE
Code:function CheckFileSize()
{
var objSize = new ActiveXObject("Scripting.FileSystemObject");
var strFileName = objSize.getFile(pathToFile);
var SizeOfFile = strFileName.size;
alert(SizeOfFile + " bytes");
}
For PHP, you'd have to upload the file to server first, and then check the size.
For that you have a filesize() function.
http://www.php.net/manual/en/function.filesize.phpPHP Code:<?php
// outputs e.g. somefile.txt: 1024 bytes
$filename = 'somefile.txt';
echo $filename . ': ' . filesize($filename) . ' bytes';
?>