Limit Photo Size on Upload

Jim Ault jimaultwins at yahoo.com
Fri Nov 6 10:40:53 EST 2009


On Nov 5, 2009, at 9:12 PM, Sivakatirswami wrote:

> Thanks to Sarah's wonderful example I'm building a little photo  
> uploader.
> ( I don't understand all the parsing of the multipart form data,  
> exactly, but enough to customize
> for my needs...)
It is just like sending several params to a function, but in this case  
you need a boundary string that cannot be accidentally included in the  
data being transferred.
The boundary string is the same as a comma in Rev.
The another requirement is to tell the server which kind of data each  
part is, thus the server can call the right program to decode and  
handle image data, text, php script,

After all, to send data to the server correctly, encoding has to be  
done, then decoded if necessary, or stored and decoded later.  Email  
is done exactly the same way, but we don't see this since the email  
programs we use hide the ugly part with a fancy UI.

If you understand how emails are encoded before hitting the internet,  
you get a little insight into using multipart form data.
>
> I'm worried about abuse... maybe too paranoid... I don't know, but I  
> would like to limit file size of uploads to 2.5 MB photos.
>
> When do we do that?  I don't think a file browser
> (  <input name="image" type="file" size="25" />) knows how big the  
> file is to actually stop the upload...
>
> so you have to handle it *after* receiving the post, right?
>
> if $_POST_RAW is not empty then
> # includes headers and filename and caption of course but no need be  
> too precise
> if len($_POST_RAW) > 2636822 then
> # exit out of processing the post
> # and return some response to the user "File Too Big."
>
> have I got this right?
One solution is use form validation in the browser before sending.
Here is a link to the Apple developer site showing a javascript example.
       http://developer.apple.com/internet/webcontent/validation.html
Also, try Googling "html form validation" for hundreds of sites with  
info.

If a Rev plugin is present, you could use Rev to check the size

Jim Ault
Las Vegas






More information about the use-livecode mailing list