Author Topic: File upload failed.  (Read 7777 times)

Offline adb101

  • Jr. Member
  • **
  • Posts: 10
File upload failed.
« on: January 24, 2017, 12:58:47 PM »
I'm hoping someone can help. Ever since I installed version 1.1.3 I've had issues attaching files to emails. Attaching a file results in "File upload failed.". I can see the apache user writing a file out to the "temp" directory, but it is always zero size. I have loosened the permissions to 777 and, clearly, the web server can write to the area but, for some reason, doesn't write any content. I have upgraded to version 1.2.3 and I'm still getting the issue.

From the php.ini side of things I've got the following settings:

; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
upload_tmp_dir = /tmp

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 50M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20


Files in roundcube temp look like:

[root@xore temp]# ls -l
total 0
-rw------- 1 apache apache 0 Jan 24 11:37 rcmAttmntUOgZnX
-rw------- 1 apache apache 0 Jan 24 17:47 rcmAttmntfYm0s2
-rw------- 1 apache apache 0 Jan 24 11:35 rcmAttmntmKjVRN
-rw------- 1 apache apache 0 Jan 24 11:41 rcmAttmntxtvs1S


SELinux is disabled.

As an aside, I have Horde installed on the same server and that does not have any issues with attachments.

I have put the Roundcube logging to max but nothing is being written to the logs directory about the file upload failing.

If anyone could suggest how I can get any additional debug or what to try next I'd me most grateful as it's driving me nuts!

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,556
    • http://SKaero.com/
Re: File upload failed.
« Reply #1 on: January 24, 2017, 01:13:34 PM »
What is your post_max_size?

Offline adb101

  • Jr. Member
  • **
  • Posts: 10
Re: File upload failed.
« Reply #2 on: January 24, 2017, 03:18:40 PM »
post_max_size is not set in php.ini.

Other apps, such as Horde, are posting attachments fine with the same php.ini settings...

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,556
    • http://SKaero.com/
Re: File upload failed.
« Reply #3 on: January 24, 2017, 03:37:05 PM »
That could be the problem, post_max_size needs to larger then upload_max_filesize size since files are in the post data. Horde most likely has it's own php.ini, .htaccess or is overwriting the setting at run time.

Offline adb101

  • Jr. Member
  • **
  • Posts: 10
Re: File upload failed.
« Reply #4 on: January 25, 2017, 03:52:18 AM »
Yes, good point. I have checked those and made them the same, but still getting the issue (any file attachment, any size).

I have narrowed the issue down to this code in ./program/steps/mail/attachments.inc:

      else {  // upload failed
            if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) {
                $size = $RCMAIL->show_bytes(rcube_utils::max_upload_size());
                $msg  = $RCMAIL->gettext(array('name' => 'filesizeerror', 'vars' => array('size' => $size)));
            }
            else if ($attachment['error']) {
                $msg = $attachment['error'];
            }
            else {
                $msg = $RCMAIL->gettext('fileuploaderror');
            }

            if ($attachment['error'] || $err != UPLOAD_ERR_NO_FILE) {
                $OUTPUT->command('display_message', $msg, 'error');    <---THIS LINE IS GENERATING THE ERROR MSG ON SCREEN
                $OUTPUT->command('remove_from_attachment_list', $uploadid);
            }


I have put some debug in and $err is coming back as "0". Unfortunately I've got extremely limited PHP experience so if anyone can suggest some additional debug to add to this section to actually work out what the issue is I'd be grateful.

Thanks!

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,556
    • http://SKaero.com/
Re: File upload failed.
« Reply #5 on: January 25, 2017, 05:17:56 AM »
This sounds like a permissions problem, what is the exact error message in the error log?

Offline adb101

  • Jr. Member
  • **
  • Posts: 10
Re: File upload failed.
« Reply #6 on: January 25, 2017, 06:00:01 AM »
Unfortunately the error log is not writing anything when the error occurs. I have the following debug settings for roundcube set in config_inc.php:

// ----------------------------------
// LOGGING/DEBUGGING
// ----------------------------------
// system error reporting, sum of: 1 = log; 4 = show
$config['debug_level'] = 1;

  // Log SQL queries to <log_dir>/sql or to syslog
  $config['sql_debug'] = true;

  // Log IMAP conversation to <log_dir>/imap or to syslog
  $config['imap_debug'] = true;

  // Log LDAP conversation to <log_dir>/ldap or to syslog
  $config['ldap_debug'] = true;

  // Log SMTP conversation to <log_dir>/smtp or to syslog
  $config['smtp_debug'] = true;


Nothing being written to the error log  :(

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,556
    • http://SKaero.com/
Re: File upload failed.
« Reply #7 on: January 25, 2017, 06:05:29 AM »
It definitely sounds like a permissions problem, if Roundcube isn't writing anything to the log then it most likely doesn't have access. If Roundcube doesn't have access to write to the temp folder then it wont be able to add attachments.

Offline adb101

  • Jr. Member
  • **
  • Posts: 10
Re: File upload failed.
« Reply #8 on: January 25, 2017, 06:54:35 AM »
But it is writing to the other logs in that directory?

[root@xore logs]# ls -l
total 163636
-rw-rw-rw- 1 root root      4707 Jan 23 10:30 errors    <-- Contains just user login error messages
-rw-rw-rw- 1 root root 161504231 Jan 25 11:48 imap
-rw-rw-rw- 1 root root     30812 Jan 24 09:11 sendmail
-rw-rw-rw- 1 root root   5993827 Jan 25 11:48 sql


It is able to write to the "temp" directory as the files appear, but are zero length:

[root@xore temp]# ls -lt | head
total 0
-rw------- 1 apache apache 0 Jan 25 11:05 rcmAttmntpDOyC5
-rw------- 1 apache apache 0 Jan 25 11:04 rcmAttmntPVOp07
-rw------- 1 apache apache 0 Jan 25 11:03 rcmAttmntfRwYtt
-rw------- 1 apache apache 0 Jan 25 11:02 rcmAttmntC8DNeO
-rw------- 1 apache apache 0 Jan 25 08:49 rcmAttmntw6ini7
-rw------- 1 apache apache 0 Jan 25 08:45 rcmAttmntrCVke1
-rw------- 1 apache apache 0 Jan 25 08:37 rcmAttmntVRsid7
-rw------- 1 apache apache 0 Jan 25 08:34 rcmAttmntS6wxNt
-rw------- 1 apache apache 0 Jan 25 08:33 rcmAttmntelSjdR


The filesystem the roundcube installation directory resides in has no special restrictions:

[root@xore temp]# mount
/dev/mapper/VolGroup00-LvRoot on / type ext4 (rw,user_xattr,acl)


Unless roundcube is trying to open some sort of special pipe or other construct to write files in "temp" which the OS is blocking..? Without any useful error message I'm a bit stuck...

Thanks.

Offline rm13

  • Full Member
  • ***
  • Posts: 129
Re: File upload failed.
« Reply #9 on: January 27, 2017, 12:09:32 AM »
Possibly the htaccess file. These php values may be set there.

php_value   upload_max_filesize   
php_value   post_max_size         
php_value   memory_limit         

Do your apache logs have any php errors that may shed some light?

Offline adb101

  • Jr. Member
  • **
  • Posts: 10
Re: File upload failed.
« Reply #10 on: February 02, 2017, 04:58:00 AM »
Unfortunately there seems to be a complete lack of logging for this error, hence by difficultly in tracking down the issue!

I've set the following values in the .htaccess file in the RC directory:

php_flag    display_errors  On
php_flag    log_errors      On
php_value    error_log    logs/errors

php_value   upload_max_filesize   50M
php_value   post_max_size         50M
php_value   memory_limit          128M


As I mentioned before, the attachment file gets "touched" in the directory but there is no data inside it. This indicates that the process has write access.

Horde, which I have installed on the same server, can upload file attachments but I prefer the RC interface ;) The htaccess settings are the same for RC and Horde (in respect to the above values).

Thanks

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,314
Re: File upload failed.
« Reply #11 on: February 02, 2017, 07:12:12 AM »
are you running any roundcube plugins? if so make sure you try with them all disabled.
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and moreā€¦

Offline m_rc_b

  • Newbie
  • *
  • Posts: 1
Re: File upload failed.
« Reply #12 on: June 28, 2017, 12:50:06 PM »
Just in case anyone else has the "File upload failed" problem, my own experiences might help a percentage of cases.

It is not just the PHP file (.../attachments.inc) that uses the (English language) message "File upload failed", it is also used in app.min.js, which then lead me down the path I followed. Using Firefox debugger, I could see when and where the message was occurring and then found that it was that a JavaScript failure to access an iframe document (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Property_access_denied?utm_source=mozilla&utm_medium=firefox-console-errors&utm_campaign=default). After further investigation, I see that in my web server's configuration file for SSL, it was FORCING an HTTP header (X-FRAME-OPTIONS) always to DENY - even adding in "sameorigin" in to the RoundCube config options only caused the header to become invalid: DENY, sameorigin.  So, I ended up amending the web server's config file, restart the web server, reload the RoundCube page and problem solved.

Hope this helps.

Offline ljbomir

  • Newbie
  • *
  • Posts: 1
Re: File upload failed.
« Reply #13 on: July 11, 2017, 12:27:42 PM »
@adb101, Did you manage resolving your problem ?

I've been struggling to find out any clue on the same.

X-FRAME-OPTIONS is correctly set to "sameorigin" in the header. I have tried also disabling it without any results.

The biggest pain is that I can not get a single error message in /var/log/roundcube/, neither in /var/log/apache2/domain-name/, neither in /var/log/apache2/ !

I can only upload some small ascii files which are being uploaded in /var/lib/roundcube/temp folder.
For all the rest it fails.

Any help on enabling logging for this specific upload action will be much appreciated.

Thanks
Lyubo
« Last Edit: July 11, 2017, 12:33:31 PM by ljbomir »

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,556
    • http://SKaero.com/
Re: File upload failed.
« Reply #14 on: July 11, 2017, 01:26:45 PM »
If you create a file with the following:
Code: [Select]
<?php
phpinfo
();

What is returned?