CodeIgniter Forums
Need help to get file size while uploading - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Need help to get file size while uploading (/showthread.php?tid=10499)



Need help to get file size while uploading - El Forum - 08-02-2008

[eluser]nandish[/eluser]
I try to avoid uploading images according to file size but the thing is am not able to get file size with the help of javascript



function getFilesize(){
var size = document.images['uimgs'].fileSize;
return size;
}
function validate(){
alert(getFilesize()Wink;
}
If i run this script its return undefined in both IE AND FIREFOX


Thanks in Advance


Need help to get file size while uploading - El Forum - 08-02-2008

[eluser]Yash[/eluser]
Only IE supports javascript using activeX power.
Code:
<html>
<head>
[removed]
function A()
{
var oas = new ActiveXObject("Scripting.FileSystemObject");
var d = document.a.b.value;
var e = oas.getFile(d);
var f = e.size;
alert(f + " bytes");
}
[removed]
</head>
<body>
<form name="a">
<input type="file" name="b">
<input type="button" name="c" value="SIZE">
</form>
</body>
</html>

For others use FTP class


Need help to get file size while uploading - El Forum - 08-02-2008

[eluser]Colin Williams[/eluser]
You could silently (asynchronously) post the upload form to an iframe, which figures out the size on the server and reports back via the iframe. Although, it sounds like you want to avoid the initial upload altogether if the file is too big.

A viable solution might be to use ini_set() and lower the max_upload_size setting for this particular process (in the particular Controller method that handles the upload).