max_size in upload form

Archived from the Transloadit support forum. Originally posted on December 24, 2011; details may be outdated, see our docs for current behavior. Original thread

Hi

I would like to implement the max_size option in my upload form, but cannot make this feature work. I would like the user to be stopped from uploading the whole video before being stopped, and told that the file is too large.

Can you provide a quick example of the hidden fields in which this should appear in the html/php form?

Thanks

Hey sportshound,

in your hidden “params” input field you provide json in the form of

{ auth: {},
template_id: ‘test’
}

etc. In the “auth” portion, add “max_size: [[value]]” where [[value]] is a value representing the number of bytes you want to allow. So if you want to allow 50MB files, then the value would be 50 * 1024 * 1024.

Let me know if that helps.

Tim

Tim,

Thank you for your email, however I cannot make this work!

Here is my code

$params = array(
'auth' => array('key' => 'REDACTED'),
'template_id' => 'REDACTED',
'redirect_url' => 'http://www.sportshound.co.uk/wordpress/video%5Fuploaded.php'
);

Can you tell me where to insert the max_value?

Many thanks

sportshound

Hey,

as I said, insert it as ‘max_size’: 52428800;
into the “auth” part. This would be for 50MB.

Kind regards
Tim

Thank you Tim,

This (of course) does work.

If I may, I have one follow up question…

On my site each user has a variable $upload_limit associated with their profile (eg. $upload_limit = 1000000;), and this will vary per user type. Is it possible to pass this variable into ‘max_size’ in order to differentiate allowed maximum file uploads?

Many thanks for all of your help

Hey,

well you pass the value into your hidden form input field. So if you have any server side scripting language available (like php), you can calculate the passed value in php depending on the logged in user.

Kind regards
Tim

Closing this for now. Feel free to reply and re-open the discussion if you need further help.