Hi am trying code givrn below for checking the size of a file. But it is working well in IE 6.0. But is it not compatible with other browsers plz give a solution can this problem is solved in other browsers var oas = new ActiveXObject("Scripting.FileSystemObject"); <html> <head> <h2>Check the code below, ActiveX will create sometimes problem.</h2> <script type ="text/javascript" > function A() { var oas = new ActiveXObject("Scripting.FileSystemObject"); var d = document.a.b.value; var e = oas.getFile(d); var g var f = e.size; alert(f/1024 + " Kilo-bytes"); } </script> </head> <body> <form name="a"> <input type="file" name="b"> <input type="button" name="c" value="SIZE" onClick="A();"> </form> </body> </html>
ActiveX Objects are only supported on IE. And I don't think there's another way to do that with Javascript.
I tried to follow the php manual but cant make it <!-- The data encoding type, enctype, MUST be specified as below --> <form enctype="multipart/form-data" action="receive.php" method="POST"> <!-- MAX_FILE_SIZE must precede the file input field --> <input type="hidden" name="MAX_FILE_SIZE" value="30" /> <!-- Name of input element determines name in $_FILES array --> Send this file: <input name="userfile" type="file" /> <input type="submit" value="Send File" /> </form> PHP: the form submit to <?php $uploaddir = '/var/www/html/xxx/web/temp/vd'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); echo '<pre>'; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "Possible file upload attack!\n"; } echo 'Here is some more debugging info:'; print_r($_FILES); print "</pre>"; ?> PHP: I still waiting like hell I am sure lots of ppl hoping can check file size without waiting it to fully uploaded i even sad when i found this http://forum.atlantaphp.org/index.php/m/1215/
You could use a Flash uploader. Flash's file system can get the file sizes. As for your PHP script, there should be a slash at the end of the upload path.
Because PHP is a server side language, and it can't check the file's size without having it uploaded fully to the server.
You can do it with PERL (server side). Checking the environment variable: my $data_length = $ENV{'CONTENT_LENGTH'} if len is ok, then you can continue with: read(STDIN, $buffer, $data_length); if not, just die.
Is it Perl language, or PERL(a php function)? I cant find PERL function in php manual If it's a Perl language, how can i use PHP to run Perl script? Coz my website is coded in PHP Thanks
It's Perl Language. Probably on your hosting you can run Perl programs. The first line of Perl programs is something like this: #! /usr/bin/perl
PHP can do it too, if he was looking for a server-side solution. Try finding a Flash or Java (Not Javascript) uploader. That'll be the only way to achieve what you want.
Use $_SERVER['CONTENT_LENGTH'] after trying to upload file. This variable returns size of uploaded file, even if upload failed
I have the way to fix for FireFox, but is it not compatible with other browsers(IE, chrome,safari,...) <html> <head><title>This is count File Size</title></head> <body> <input id="test" type="File"/> <input type="button" onclick="checkFileSize();" value="Check File Size" /> </body> <script type="text/javascript"> function checkFileSize() { var node = document.getElementById('test'); alert('fileSize = '+node.files[0].fileSize); } </script> </html>