option to set maximum size of uploaded files

git-svn-id: http://redmine.rubyforge.org/svn/trunk@131 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2007-01-01 12:09:09 +00:00
parent ff65a5b22a
commit 6487c1803f
11 changed files with 18 additions and 6 deletions

View File

@ -21,7 +21,11 @@ class Attachment < ActiveRecord::Base
belongs_to :container, :polymorphic => true belongs_to :container, :polymorphic => true
belongs_to :author, :class_name => "User", :foreign_key => "author_id" belongs_to :author, :class_name => "User", :foreign_key => "author_id"
@@max_size = $RDM_ATTACHMENT_MAX_SIZE || 5*1024*1024
cattr_reader :max_size
validates_presence_of :container, :filename validates_presence_of :container, :filename
validates_inclusion_of :filesize, :in => 1..@@max_size
def file=(incomming_file) def file=(incomming_file)
unless incomming_file.nil? unless incomming_file.nil?

View File

@ -31,7 +31,7 @@
<%= start_form_tag ({ :controller => 'documents', :action => 'add_attachment', :id => @document }, :multipart => true, :class => "tabular") %> <%= start_form_tag ({ :controller => 'documents', :action => 'add_attachment', :id => @document }, :multipart => true, :class => "tabular") %>
<p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>&nbsp; <p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>&nbsp;
<%= link_to_function image_tag('add'), "addFileField()" %></label> <%= link_to_function image_tag('add'), "addFileField()" %></label>
<%= file_field_tag 'attachments[]', :size => 30 %></p> <%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= human_size(Attachment.max_size) %>)</em></p>
<%= submit_tag l(:button_add) %> <%= submit_tag l(:button_add) %>
<%= end_form_tag %> <%= end_form_tag %>
<% end %> <% end %>

View File

@ -89,7 +89,7 @@ end %>
<%= start_form_tag ({ :controller => 'issues', :action => 'add_attachment', :id => @issue }, :multipart => true, :class => "tabular") %> <%= start_form_tag ({ :controller => 'issues', :action => 'add_attachment', :id => @issue }, :multipart => true, :class => "tabular") %>
<p id="attachments_p"><label><%=l(:label_attachment_new)%>&nbsp; <p id="attachments_p"><label><%=l(:label_attachment_new)%>&nbsp;
<%= link_to_function image_tag('add'), "addFileField()" %></label> <%= link_to_function image_tag('add'), "addFileField()" %></label>
<%= file_field_tag 'attachments[]', :size => 30 %></p> <%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= human_size(Attachment.max_size) %>)</em></p>
<%= submit_tag l(:button_add) %> <%= submit_tag l(:button_add) %>
<%= end_form_tag %> <%= end_form_tag %>
<% end %> <% end %>

View File

@ -6,7 +6,7 @@
<div class="box"> <div class="box">
<p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>&nbsp; <p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>&nbsp;
<%= link_to_function image_tag('add'), "addFileField()" %></label> <%= link_to_function image_tag('add'), "addFileField()" %></label>
<%= file_field_tag 'attachments[]', :size => 30 %></p> <%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= human_size(Attachment.max_size) %>)</em></p>
</div> </div>
<%= submit_tag l(:button_create) %> <%= submit_tag l(:button_create) %>

View File

@ -9,7 +9,7 @@
<p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>&nbsp; <p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>&nbsp;
<%= link_to_function image_tag('add'), "addFileField()" %></label> <%= link_to_function image_tag('add'), "addFileField()" %></label>
<%= file_field_tag 'attachments[]', :size => 30 %></p> <%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= human_size(Attachment.max_size) %>)</em></p>
</div> </div>
<%= submit_tag l(:button_add) %> <%= submit_tag l(:button_add) %>
<%= end_form_tag %> <%= end_form_tag %>

View File

@ -27,7 +27,7 @@
<p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>&nbsp; <p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>&nbsp;
<%= link_to_function image_tag('add'), "addFileField()" %></label> <%= link_to_function image_tag('add'), "addFileField()" %></label>
<%= file_field_tag 'attachments[]', :size => 30 %></p> <%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= human_size(Attachment.max_size) %>)</em></p>
</div> </div>
<!--[eoform:issue]--> <!--[eoform:issue]-->

View File

@ -63,3 +63,7 @@
# Textile formatting is automativaly disabled if RedCloth is not available # Textile formatting is automativaly disabled if RedCloth is not available
# Set to true to manually disable. # Set to true to manually disable.
# $RDM_TEXTILE_DISABLED = true # $RDM_TEXTILE_DISABLED = true
# Maximum size for attachments (in bytes)
# Default to 5 MB
# $RDM_ATTACHMENT_MAX_SIZE = 5*1024*1024

View File

@ -295,6 +295,7 @@ label_modified: geändert
label_deleted: gelöscht label_deleted: gelöscht
label_latest_revision: Neueste Neuausgabe label_latest_revision: Neueste Neuausgabe
label_view_revisions: Die Neuausgaben ansehen label_view_revisions: Die Neuausgaben ansehen
label_max_size: Maximale Größe
button_login: Einloggen button_login: Einloggen
button_submit: Einreichen button_submit: Einreichen

View File

@ -295,6 +295,7 @@ label_modified: modified
label_deleted: deleted label_deleted: deleted
label_latest_revision: Latest revision label_latest_revision: Latest revision
label_view_revisions: View revisions label_view_revisions: View revisions
label_max_size: Maximum size
button_login: Login button_login: Login
button_submit: Submit button_submit: Submit

View File

@ -295,6 +295,7 @@ label_modified: modificado
label_deleted: suprimido label_deleted: suprimido
label_latest_revision: La revisión más última label_latest_revision: La revisión más última
label_view_revisions: Ver las revisiones label_view_revisions: Ver las revisiones
label_max_size: Tamaño máximo
button_login: Conexión button_login: Conexión
button_submit: Someter button_submit: Someter

View File

@ -296,6 +296,7 @@ label_modified: modifié
label_deleted: supprimé label_deleted: supprimé
label_latest_revision: Dernière révision label_latest_revision: Dernière révision
label_view_revisions: Voir les révisions label_view_revisions: Voir les révisions
label_max_size: Taille maximale
button_login: Connexion button_login: Connexion
button_submit: Soumettre button_submit: Soumettre