--- filefield_old.module	2007-05-04 15:59:49.000000000 -0400
+++ filefield.module	2007-05-04 15:50:54.000000000 -0400
@@ -215,14 +215,53 @@ function filefield_widget_settings($op, 
         '#maxlength' => 64, 
         '#description' => t('Extensions a user can upload to this field. Seperate extensions with a space and do not include the leading dot.')
       );
+      $form['image_path'] = array(
+        '#type' => 'textfield', 
+        '#title' => t('File path'), 
+        '#default_value' => $widget['file_path'] ? $widget['file_path'] : '', 
+        '#description' => t('Optional subdirectory within the "%dir" directory where files will be stored. Do not include trailing slash.', array('%dir' => variable_get('file_directory_path', 'files'))), 
+        '#after_build' => array('filefield_form_check_directory'),
+      );
       return $form;
     case 'validate':
       break;
     case 'save':
-      return array('file_extensions');
+      return array('file_extensions', 'file_path');
   }
 }
 
+/**
+ * Wrapper function for filefield_check_directory that accepts a form element
+ * to validate - if user specified one. Won't allow form submit unless the
+ * directory exists & is writable
+ * 
+ * @param $form_element
+ *   The form element containing the name of the directory to check.
+ */
+function filefield_form_check_directory($form_element) {
+  if(!empty($form_element['#value'])) {
+    filefield_check_directory($form_element['#value'], $form_element);
+  }
+  return $form_element;
+}
+
+/**
+ * Create the file directory relative to the 'files' dir recursively for every
+ * directory in the path.
+ * 
+ * @param $directory
+ *   The directory path under files to check, such as 'photo/path/here'
+ * @param $form_element
+ *   A form element to throw an error on if the directory is not writable
+ */ 
+function filefield_check_directory($directory, $form_element = array()) {
+  foreach(explode('/', $directory) as $dir) {
+    $dirs[] = $dir;
+    $path = file_create_path(implode($dirs,'/'));
+    file_check_directory($path, FILE_CREATE_DIRECTORY, $form_element['#parents'][0]);
+  }
+  return true;
+}
 
 function filefield_clear_session() {
   if (is_array($_SESSION['filefield']) && count($_SESSION['filefield'])) {
