MAX_FILE_SIZE (Uploading Multiple Files)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zenabi
Forum Commoner
Posts: 84
Joined: Mon Sep 08, 2003 5:26 am
Location: UK

MAX_FILE_SIZE (Uploading Multiple Files)

Post by zenabi »

This is an example of a HTML form for uploading a file, similar to the one on php.net.

Code: Select all

<form enctype="multipart/form-data" action="_URL_" method="post">
   <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
   File 1: <input name="userfile" type="file" />
   <input type="submit" value="Send" />
</form>
Now say I wanted to upload two files at once, but each with a different maximum file size setting, I will have something like this:

Code: Select all

<form enctype="multipart/form-data" action="_URL_" method="post">
   <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
   File 1: <input name="userfile1" type="file" />

   <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
   File 2: <input name="userfile2" type="file" />

   <input type="submit" value="Send" />
</form>
Notice there are now two hidden input elements with the same name (MAX_FILE_SIZE). Am I correct in saying that the second hidden input element would take precedence over the first and effectively make both inputs have the same maximum file size?

Apologies if that was explained badly :oops: , but I would be very grateful if someone could find a way to have each input element with its own maximum file size setting.
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

I think it can't be that way you wrote. But you can check it with PHP after you post it.

You can check the files' sizes both. and return an error.

$_FILES['userfile']['size']
zenabi
Forum Commoner
Posts: 84
Joined: Mon Sep 08, 2003 5:26 am
Location: UK

Post by zenabi »

Thanks for the quick reply!

I have thought of your way, but I want the users to know their files are too big before they upload them.

Any ideas?
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

well you cannot do it via Javascript onlu ActiveX in IE (that sux)... I think you should use PHP for validation; with that MAX_FILE_SIZE... I don't think it works..
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

yuo could use multiple forms, and have the submit button on the last one submit all of thenm, but i'm not sure if it's possible...
Post Reply