欢迎各位兄弟 发布技术文章
这里的技术是共享的
function tag_graphics_form($form_state) {
$form = array();
$form['#attributes'] = array('enctype' => "multipart/form-data");
$form['tag'] = array(
'#required' => TRUE,
'#type' => 'textfield',
'#title' => t('Tag'),
'#size' => 30,
);
$form['image'] = array(
'#type' => 'file',
'#title' => t('Image for tag page'),
'#description' => 'Recommended width for image: 605px'
);
$form['description'] = array(
'#type' => 'textarea',
'#title' => t('Page Description for SEO')
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Save'
);
return $form;
}
function tag_graphics_form_validate($form, &$form_state){
$field = 'image';
$directory = file_directory_path();
if (file_check_directory($directory, FILE_CREATE_DIRECTORY, $field)) {
$validators = array();
if ($file = file_save_upload($field, $validators, $directory)) {
file_set_status($file, FILE_STATUS_PERMANENT);
$form_state['storage']['file'] = $file;
}
}
}
function tag_graphics_form_submit(&$form, &$form_state){
print_r($form_state['storage']['file']);
}
来自 http://drupal.stackexchange.com/questions/130152/file-upload-empty-in-custom-form
This is not too difficult, you can see some info here. An example of a form with only a file upload.
function myform_form($form_state) {
$form = array('#attributes' => array('enctype' => 'multipart/form-data'));
$form['file'] = array(
'#type' => 'file',
'#title' => t('Upload video'),
'#size' => 48,
'#description' => t('Pick a video file to upload.'),
);
return $form;
}
EDIT:
Now to save the file use the file_save_upload function:
function myform_form_submit($form, $form_state) {
$validators = array();
$file = file_save_upload('file', $validators, 'path');
file_set_status($file, FILE_STATUS_PERMANENT);
}
2nd EDIT:
There's a lot of questions and ways to do the things you described. I wont go to much into the actual code of how to handle a csv file. What I would suggest is that you use the file id to keep track of the file. That would enable you to make urls that take a fid and use that to load the file you want to work on. To get from your form to the next step, you can use the #redirect form property to get your users to the next step. From there is really depends how you do things, what you'll need to do.
来自 http://stackoverflow.com/questions/1253094/howto-drupal-file-upload-form