Maximum File Size Upload

zzzj_2812

New Member
Messages
10
Reaction score
0
Points
0
Hello all!

I would like some help with a performance issue: the upload of very large files.

Here's the issue: users are able to upload avatars on a site that I am currently building. Currently, the server will check if the avatar is larger than an allowed file size, and if it is too large, the avatar will not be saved. However, this is not satisfactory for me. The server has to spend a lot of time receiving the file, only to tell the user that its not allowed. Is there any way to either:

1) Check the file size on the client side, and keep the user from uploading it, or
2) Change some configuration setting so that the server will not even start to upload files that are too large?

I know you can change some settings in php.ini to accomplish the second, but we don't have access to php.ini. Does anyone have any suggestions?
 

fomalhaut

Member
Messages
107
Reaction score
0
Points
16
Hello

First, you can add this tag as first one in the form tag, that limits the size on the client side:
HTML:
<input type="hidden" name="MAX_FILE_SIZE" value="200000" />
Naturaly, the value "200000" is an example !

On the server side, you can control the size by the $_FILES function:
PHP:
if ($_FILES['fileName']['error']==2) {
  $Tmsg = 'Too big file (it must not be greater than '.$_POST['MAX_FILE_SIZE'].' octets)';
  ...display this information or do what you want}
"fileName" is an example, too. It's the name of the file in the form tag (<input type='file', name='fileName'... />).

But I don't know really if the system on the server knows immediatly the size or if it begins the load !
Try it and eventually see the PHP documentation.

Good year
 
Last edited:

Livewire

Abuse Compliance Officer
Staff member
Messages
18,169
Reaction score
216
Points
63
@fomalhaut: If you're checking filesize on the server-side (as in via php), that's server-side, it has to upload the file first.

@OP: about the best I can recommend (I have no actual examples) is either a Javascript uploader or a similar Flash based one - both would run on the client computer and could check the filesize prior to the upload, but I've not actually looked for these in the past since I haven't needed them, so I'm not sure of any good ones to recommend.
 

garrette

New Member
Messages
27
Reaction score
0
Points
0
I don't believe x10hosting allows for file storage

That would be correct if he was storing these files for download. The terms of service state that this can't be used to host scripts such as torrentflux. It also states that it is alright to host files, as long as they have to do with the website. Now if this website gets too large and overuses it's share of file storage, then that's a whole different situation.

What he is asking doesn't violate the ToS, since he is not hosting these files for download, they deal with his site.
 

zzzj_2812

New Member
Messages
10
Reaction score
0
Points
0
@ellescuba27: that would be a little nuts, since pretty much every site of any type needs some type of file storage.
@fomalhaut: thanks for the suggestions, but I already have server-side checks such as that in place :(
@Livewire: I did a little googling about a JS uploader, but apparently JS is not able to access the file system, and as such, can't check the file size. I would like to avoid using flash if possible. Any other suggestions?
 
Top