[support] File attachment without NID
    pavithra 
    pavspavi88 at gmail.com
       
    Tue Feb  8 09:25:14 UTC 2011
    
    
  
The below code does file attachement without nid....I want this to be
looped..as we get the "File Attachment option " in page content type when we
enable the Upload module..
I am trying to do file upload without nid created....
Thanks for your kind help in achieving this..
function my_form(&$form_state)
{
$form['field1']=array(
'#title'=>'',
'#type'=>'textfield',
'#prefix'=>'<table class="formtable"><tr><td class="labeltext">FIELD
1</td><td class="textbox">',
'#suffix'=>'</td></tr></table>',
  );
   $form['#attributes']['enctype'] = "multipart/form-data";
  // add a file upload file
  $form['upload'] = array(
    '#type' => 'file',
    //'#title' => t('Attach a file'),
'#prefix'=>'<tr><td class="labeltext">Attach a file</td><td
class="textbox">',
'#suffix'=>'</td></tr></table>'
  );
  // add a submit button
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Attach a file and submit',
  );
  return $form;
  }
function my_form_validate($form, &$form_state) {
  // define upload field name
  // NOTE: this should match the name of your form file field
  $fieldName = 'upload';
  // If a file was uploaded, process it.
  if (isset($_FILES['files']) &&
is_uploaded_file($_FILES['files']['tmp_name'][$fieldName])) {
    // attempt to save the uploaded file
    $file = file_save_upload($fieldName);
    // set error if file was not uploaded
    if (!$file) {
      form_set_error($fieldName, 'Error uploading file.');
      return;
    }
    // set files to form_state, to process when form is submitted
    $form_state['values']['file'] = $file;
  }
  else {
    // set error
    form_set_error($fieldName, 'Error uploading file.');
    return;
  }
  }
 function my_form_submit($form, &$form_state) {
  $file =$form_state['values']['file'] ;
 file_set_status($file, FILE_STATUS_PERMANENT);
db_query("INSERT INTO {table3} VALUES
('%s')",$form_state['values']['productcode']);
 }
-- 
*Cheers
**
*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20110208/6359968f/attachment-0001.html 
    
    
More information about the support
mailing list