How to specify subdirectory for uploads in files dir when adding file field to content type via module?
It seems to me that your directory does not exists (or at least is not writable).
You can make a function to test/create your custom folder:


function create_directory($folder) {
   // Constructs a URI to Drupal's default files location given a relative path
   $dir = file_build_uri($folder);
   // Checks that the directory exists and is writable.
   // Indicate if the directory should be created if it does not exist (FILE_CREATE_DIRECTORY) or made writable if it is read-only (FILE_MODIFY_PERMISSIONS)
   $res = file_prepare_directory($dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
   if (!$res) {
     watchdog('file system', 'The directory %directory does not exist or is not writable.', array('%directory' =&gt; $dir), WATCHDOG_ERROR);
   }
   return $res;

}




Then call this function with $type as parameter: create_directory($type);