Digital Point Forums
San Diego Models

Go Back   Digital Point Forums > Design & Development > Programming > JavaScript
Google Analytics
Log In to view
your analytics

Reply
 
Thread Tools
  #1  
Old Dec 22nd 2004, 12:06 am
anton-io!'s Avatar
anton-io! anton-io! is offline
Twilight Vanquisher
 
Join Date: Dec 2004
Location: Vancou-vah!
Posts: 530
anton-io! will become famous soon enough
Check file size before upload?

Looking for a client side script that will check the file size of a user selected file (i.e., image) before it is uploaded to the server.

Possible in Javascript?

Looking for a Javascript/PHP solution or a simple PHP solution if possible.

Thanks greatly!
__________________
Post Free Ads * Wed Design Pros *

Reply With Quote
  #2  
Old Dec 23rd 2004, 12:22 am
nevetS's Avatar
nevetS nevetS is offline
Evolving Dragon
 
Join Date: Nov 2004
Location: Southern California
Posts: 2,539
nevetS is a name known to allnevetS is a name known to allnevetS is a name known to allnevetS is a name known to allnevetS is a name known to allnevetS is a name known to all
php is all server side scripting, so you are out of luck in that regard. Somebody correct me if I'm wrong, but there is no way to check a file size in php prior to upload. You can set a parameter in your php.ini file that I believe is MAX_UPLOAD or MAX_FILE_UPLOAD to 1 megabyte or another arbitrary number if you want. If someone tried to upload a larger file, they would get an error.

On the javascript/vbscript side, I believe that you are looking for information that is not available via those scripting languages either.

Your only option would be java if you wanted to check something client side.

I could be wrong, though. It's happened before (twice) .
__________________
Reply With Quote
  #3  
Old Dec 23rd 2004, 1:56 am
dustin's Avatar
dustin dustin is offline
Grunt
 
Join Date: Dec 2004
Location: Vancouver
Posts: 69
dustin is on a distinguished road
Java applets have a pretty strict security policy in place. It prevents them from doing nasty things to the computers of people who view them. So I'm not sure if they would be able to check an image's size.
__________________
Lux: Online Risk Board Game | Strategy Games | |
Reply With Quote
  #4  
Old Jan 15th 2005, 5:50 pm
relaxzoolander's Avatar
relaxzoolander relaxzoolander is offline
Champion of the Naaru
 
Join Date: Apr 2004
Location: columbus, ohio
Posts: 141
relaxzoolander is on a distinguished road
asp file upload

i use an asp script that checks file size.
.
Reply With Quote
  #5  
Old Jan 18th 2005, 1:26 am
phrozen_ra phrozen_ra is offline
Champion of the Naaru
 
Join Date: Jan 2005
Posts: 147
phrozen_ra is an unknown quantity at this point
http://ro.php.net/features.file-upload

with PHP and it's not that difficult... if you still don't understand i'll help you
__________________
Funny Quotations | Reading Glasses |
Reply With Quote
  #6  
Old Apr 10th 2008, 8:32 am
RussellMD RussellMD is offline
Peon
 
Join Date: Apr 2008
Posts: 2
RussellMD is on a distinguished road
Wink Use PHP

Hi!

You can use a server-side solution.

Use $_SERVER['CONTENT_LENGTH'] after trying to upload file. This variable returns size of uploaded file, even if upload failed


if(isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH']>2097152)
$error = 'Upload FAILED, file is too large !';

This method work fine for all cases of errors when upload file , even if filesize is greater than MAX_FILE_SIZE, upload_max_filesize or post_max_size (from php.ini)

Good Luck! && Sorry for my bad english.
Reply With Quote
  #7  
Old Apr 11th 2008, 9:02 pm
dineshw dineshw is offline
Peon
 
Join Date: Apr 2008
Posts: 1
dineshw is on a distinguished road
RussellMD,

Wont that only check the file size AFTER the file has already been uploaded to the temporary folder? Doesnt that defeat the purpose?

Dinesh
Reply With Quote
  #8  
Old Jan 1st 2009, 3:58 am
yangyang yangyang is offline
Banned
 
Join Date: Feb 2007
Location: KaVoir.com
Posts: 759
yangyang will become famous soon enoughyangyang will become famous soon enough
JavaScript is not able to do it, it's forbidden to access file system.

However with VBScript on ActiveX object, you can check for file size with client side scripting. Hope the code below helps:

html4strict Code:
<head><script>
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");
}

</script>
</head>
<body>
<form name="a">
<input type="file" name="b">
<input type="button" name="c" value="SIZE" onClick="A();">
</form>
</body>
</html>

Last edited by yangyang; Jan 1st 2009 at 4:23 am.
Reply With Quote
  #9  
Old Jan 1st 2009, 1:15 pm
dimitar christoff's Avatar
dimitar christoff dimitar christoff is online now
Twilight Vanquisher
 
Join Date: Sep 2008
Location: London
Posts: 669
dimitar christoff has a spectacular aura aboutdimitar christoff has a spectacular aura about
activex / vbscript is not cross browser and reliant on security limitations.
checking server side is daft - if you have a limit of say, 5mb and somebody uploads a 5.2 mb file, it means waiting for the whole upload to complete so that php/asp can say 'too big, try again'.

http://digitarald.de/project/fancyupload/
uses mootools and a really tiny flash control - check the demos. achieves desired check and much more, including progress report, multiple uploads etc. flash is likely to be installed for at least 90% of your visitors and the solution is semantic anyway - uses a normal form upload which can work via POST if flash is not there.
__________________
I appreciate your rep just as you may appreciate any help / advice given
fragged.org: on playing with javascript, mootools, CSS, PHP, SEO and more stuff nobody cares about
london cleaners
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding lareg numbers of frequently changing relevant pages. Owlcroft Search Engine Optimization 25 Jan 11th 2005 12:27 pm
Upload file from http post cmc@savycat.com PHP 4 Oct 8th 2004 3:15 pm
File Date + Googlebot wiseone Google 2 Jun 29th 2004 6:35 pm
Size of .htaccess File? Owlcroft Apache 6 Apr 17th 2004 7:45 am


All times are GMT -8. The time now is 12:53 am.