Attempting to ajax an interface to image.module

  1. function galLoader_form_submit($form_id, $form_values) {
  2.   $op = $_POST['op'];
  3.  
  4.  if($op == 'submit'){
  5.   $dir = 'files';
  6.           if(file_check_directory($dir)){
  7.             $save = file_save_upload('file_upload', $dir, true);
  8.             if(!$save){
  9.                 print('ERROR downloading the file to '.$dir);
  10.             } else {
  11.                 print('File successfully uploaded <br /> If this is the image you want to send in, please hit Save and Send below. Otherwise, upload another <br />');
  12.                                 print theme('imagecache', 'products','/files/'.$save->filename.'');
  13.             }
  14.             variable_set('galLoader_file', $dir.'/'.$save);
  15.         } else {
  16.             drupal_set_message( t('WARNING: Server DIR is not accessible. Consult with site admin!', 'status') );
  17.         }
  18.  } elseif($op == 'save'){
  19.        
  20.         if(variable_get('galLoader_file', NULL ) == NULL){
  21.         //no file
  22.         //print("You haven't uploaded a file!");
  23.         } else {
  24.         //pass to image.module
  25.         $node = image_create_node_from(variable_get('galLoader_file', NULL ), $form_values['title'], $form_values['body'], 'Main Gallery');
  26.         }
  27.  
  28.  }
  29.   //handle the file, using file_save_upload, or something similar
  30. }