By metabaron on
Hello,
First, I'm a newbie in module developement so please be kind with me :)
I'm trying to develop a module for my personal use which allow any user to upload a file on my server (I know, a module exist for that but my module will do more than just uploading a file.
So, here is my code:
...
$form['#attributes'] = array('enctype' => "multipart/form-data");$form['file'] = array(
'#type' => 'fieldset',
'#title' => t('File'),
'#collapsible' => TRUE, // Added
'#collapsed' => FALSE, // Added
);
$form['file']['content'] = array(
'#type' => 'file',
'#description' => "No more than 100KB.",
'#title' => 'Filename',
);
$form['next'] = array(
'#type' => 'submit',
'#value' => 'Next',
);
function ar_cards_my_form_validate($form, &$form_state) {
$validators = array(
'file_validate_is_image' => array(),
'file_validate_size' => array(30 * 1024),
);
$file=file_save_upload('content', $validators);
if (!$file) {
form_set_error('content','Error uploading file: too big or wrong file type');
//image_get_info($file->filepath);
//file_directory_path()
//form_set_error('content',file_check_directory(file_directory_path()));
}else{
file_set_status($file, 1);
}
function ar_cards_my_form_submit($form, &$form_state) {
/*
Normally, some code would go here to alter the database with the data
collected from the form. Sets a message with drupal_set_message()
to validate working code.
*/
$image_path = $form_state['values']['content'];
drupal_set_message(t('The form has been submitted.'));
drupal_set_message(t('Value: '.$image_path));
unset ($form_state['storage']); // This value must be unset for
// redirection! This is because
// $form_state['rebuild'] gets set to TRUE
// when 'storage' is set. See code sample
// #9 for more on this.
$form_state['redirect'] = 'ar_cards/upload'; // Redirects the user.
}
But it seems that I can upload a file which is 500k event if, I think, I said in the code that it cannot be bigger than 30k
Can someone explain it to me?
Comments
Please use <code> tags around
Please use <code> tags around your code. It makes it much easier to read.
Contact me to contract me for D7 -> D10/11 migrations.