File Field Upload Limit

greg.harvey - June 10, 2008 - 17:13

This module extends the functionality of the File Field module for CCK by adding a "Maximum file size" field to the admin form for every field of type "file". This allows you granular control over the size of files each individual CCK field can handle. If this functionality is not required for a given field (e.g. one only available to trusted users) you can simply leave it as 0 and it will use the standard File Field behaviour and take the maximum file size from the upload module settings.

Known issues

Need to override the current "maximum file size" message where it is no longer true. This can be done on a node-by-node basis, but it could do with being achieved in this module. If someone supplies a patch ahead of me creating one, I will apply it to HEAD. Here is an example of altering the form for a specific node:

<?php
function yourmodule_form_alter($form_id, &$form) {
  global
$user;
  if ((
$form_id == 'yourcontenttype_node_form') || ($form_id == 'filefield_js') {   
   
//get default upload module settings
   
$uploadsize = array();
   
$usersize = array();
    foreach (
$user->roles as $rid => $name) {
     
$uploadsize[] = variable_get("upload_uploadsize_$rid", variable_get('upload_uploadsize_default', 1)) * 1024 * 1024;
     
$usersize[] = variable_get("upload_usersize_$rid", variable_get('upload_usersize_default', 1)) * 1024 * 1024;
    }
   
$message = "You have ".format_size((max($usersize) - upload_space_used($user->uid)))." of disk space remaining";
   
   
//if there is a field-specific size limit, set the message here
   
if ((module_exists('filefield_upload_limit')) && (format_size(filefield_upload_limit_is_set('field_yourfield')) > 0)) {
     
$uploadsizestr = format_size(filefield_upload_limit_is_set('field_yourfield'));
    } else {
     
$uploadsizestr = format_size(max($uploadsize));
    }
   
   
//add the message to the form, replacing the current message
   
$form['field_yourfield']['#description'] = "Maximum permitted filesize is ". $uploadsizestr . "<br />" .
     
$message;
  }
}
?>

Releases

Official releasesDateSizeLinksStatus
5.x-1.02008-Jul-027.62 KBRecommended for 5.xThis is currently the recommended release for 5.x.
Development snapshotsDateSizeLinksStatus
5.x-1.x-dev2008-Jul-037.62 KBDevelopment snapshotDevelopment snapshots are automatically regenerated and their contents can frequently change, so they are not recommended for production use.

Resources

 
 

Drupal is a registered trademark of Dries Buytaert.