I upgraded from 5.3 to 5.4, but seems that there is problem with files: cannot attach any.
Thanks,
Expat9

Comments

jonathan_hunt’s picture

Priority: Normal » Critical

(Also see http://drupal.org/node/163643 ).

File uploads via webform seem quite broken.

If you change the field key away from the default numeric key when adding a file field, the call to _webform_validate_file() only receives the numeric cid ('1186006286') and doesn't find the file in the $_FILES array ('file1').

11:25:08 08/02/07 ident [info] _webform_validate_file: form_element=, cid=1186006286, fieldname=CV, filters=Array
11:25:08 08/02/07 ident [info] _webform_validate_file: _FILES=Array
(
    [files] => Array
        (
            [name] => Array
                (
                    [file1] => CL-2006-07-Jul-Aug.pdf
                )

            [type] => Array
                (
                    [file1] => applicaton/zip
                )

            [tmp_name] => Array
                (
                    [file1] => /tmp/php8CbEeV
                )

            [error] => Array
                (
                    [file1] => 0
                )

            [size] => Array
                (
                    [file1] => 629993
                )

        )

)

If you leave the field key as the original, then the file is accepted but (a) still doesn't appear in the Submitted form values in the email, and if you view the form submission the download link is incorrect (at least when Private files are enabled).

jlm99’s picture

Just adding that I'm having the same issue mentioned in this thread and its duplicate.

A quick, temporary fix would be much appreciated -- is there any other way for a user to email a file to a certain email address thru the front end? Thanks in advance.

kiouv’s picture

any fix ? i'm deeply interested !

jonathan_hunt’s picture

Title: File attachment » File attachment - no link in email

Assuming you have not changed the component id for the upload field, I have found that files can be uploaded as part of a webform submission but no link to the file is included in the email notification. The following change works for me, but I haven't tested it much so I don't know what the implications of changing it are. The problem is that the value of $form_values['submitted_tree'] is created in webform.module webform_client_form_submit() but the the submit handler for a file component is invoked after submitted_tree is set. Thus submitted_tree contains no info on the file submission, and nothing is emailed about the file.

--- all/modules/webform/webform.inc     (revision 4923)
+++ all/modules/webform/webform.inc     (working copy)
@@ -180,7 +180,7 @@
 
   $message .= "\n";
   $message .= t('Submitted values are');
-  $message .= theme('webform_mail_fields', '', $form_values['submitted_tree'], $node);
+  $message .= theme('webform_mail_fields', '', $form_values['submitted'], $node);
   
   $message .= "\n\n";
   $message .= t("The results of this submission may be viewed at:\n");
atipton’s picture

I have solved this issue by overriding theme_webform_create_mailmessage() in my theme. I iterate through all of the submitted form values (using $form_values['submitted'], not $form_values['submitted_tree']) and pull out ones that are file attachments -- they will be serialized PHP arrays.

function phptemplate_webform_create_mailmessage($form_values, $node, $sid) {
  $message .=  t('Submitted on') .' '. format_date(time(), 'small') ."\n";
  $message .= "\n";
  $message .= t('Submitted values are');
  $message .= theme('webform_mail_fields', '', $form_values['submitted_tree'], $node);

  $attachments = array();
  foreach ($form_values['submitted'] as $value) {
    if (substr($value, 0, 2) == "a:") {
      $file = @unserialize($value);
      if (is_array($file)) {
        $attachments[] = $file['filepath'];
      }
    }
  }

  if (!empty($attachments)) {
    $message .= "\n";
    $message .= "This submission has attached files, which may be viewed at:\n";
    foreach ($attachments as $att) {
      $message .= file_create_url($att) . "\n";
    }
  }

  return $message;
}
rafacm’s picture

The file_create_url() does not seem to generate a correct URL for filenames with spaces, which means the link in the email will not work. I fixed this with with the following workaround:

    foreach ($attachments as $att) {
      // Encode spaces so that there are no spaces in the URL and the link on the email works
      $file_url = str_replace(' ', '%20', file_create_url($att));
      $message .= $file_url . "\n";
    }

Alternatively you can patch the file_create_url() function itself. See http://drupal.org/node/154245

Gentoo7’s picture

I get the location of the folder that holds the files, but not the actual file's url.

is there a way to link to the actual file?

quicksketch’s picture

Status: Active » Fixed

The file link issue has been fixed as part of http://drupal.org/node/203099. It should be corrected in the 1.8 version. Please reopen if the problem still exists.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.