Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"No uploaded files" error on uploading specific files #1812

Closed
GiantCrocodile opened this issue May 29, 2019 · 27 comments

Comments

@GiantCrocodile
Copy link

commented May 29, 2019

Describe the bug
Some files are not able to be uploaded because a "No uploaded files" error is thrown. This must be Windows or PHP 7.x (I think 7.3 or 7.2) specific bug.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new default page
  2. Try to upload this file (https://send.firefox.com/download/45cc9d7ebef77dce/#VOT4tDtRhx43x3y-U1pkFA, password: kirby)
  3. See error

Expected behavior
File is uploaded.

Screenshots
If applicable, add screenshots to help explain your problem.

Kirby Version
3.1.4

Console output
grafik
grafik
grafik

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Firefox
  • Version: 67.0

Additional context
We tried to debug this but we found no reason/solution. See this thread: https://forum.getkirby.com/t/what-does-this-error-on-upload-mean-no-uploaded-files/14380

Issue happens with XAMPP and Wampserver.

@GiantCrocodile

This comment has been minimized.

Copy link
Author

commented May 29, 2019

default.yml:

title: Default Page
preset: page
fields:
  text:
    label: Text
    type: textarea
    size: large
    required: true
  author:
    type: users
    required: true
  sources:
    type: structure
    fields:
        source:
            placeholder: http://google.de/...
            required: true
            type: text
        retrieved:
            placeholder: date
            type: date
            required: true
            label: Retrieved On
  tags:
    type: tags
    required: true
    min: 1
    max: 5
  published:
    type: date
    required: true
    label: Published On
    min: 01.01.2019
    max: 01.01.2019
@distantnative

This comment has been minimized.

Copy link
Contributor

commented Aug 23, 2019

@GiantCrocodile Sorry that we are only now get to this, but unfortunately the download link has expired.

@GiantCrocodile

This comment has been minimized.

Copy link
Author

commented Aug 24, 2019

@distantnative I've sent the problematic file via email to support@... for privacy reasons as I'm not sure if removing the meta data would reduce the chance to reproduce this bug. If you don't have access to support@..., please provide a private way for contact. Feel free to contact me in the forum (user: warg).

@distantnative

This comment has been minimized.

Copy link
Contributor

commented Aug 24, 2019

Ah only Bastian has access to that one. Can you send it to nico@getkirby.com? Thanks

@GiantCrocodile

This comment has been minimized.

Copy link
Author

commented Aug 29, 2019

Did you receive the file @distantnative? Any news on this?

@distantnative

This comment has been minimized.

Copy link
Contributor

commented Aug 30, 2019

I did but my weeks in my regular job have been very hectic which is why I haven't found the time to look into it unfortunately.

@GiantCrocodile

This comment has been minimized.

Copy link
Author

commented Aug 30, 2019

That's fine @distantnative; I was just asking because of the missing information label.

@bastianallgeier

This comment has been minimized.

Copy link
Contributor

commented Sep 5, 2019

@GiantCrocodile I just tested the file you sent me and it's uploaded without any issues. It really seems like a specific Windows issue. Super difficult to debug.

@afbora

This comment has been minimized.

Copy link
Contributor

commented Sep 5, 2019

I can also test it on windows machine if you want 👍

@bastianallgeier

This comment has been minimized.

Copy link
Contributor

commented Sep 5, 2019

@afbora if @GiantCrocodile is ok with that I can forward it to you via Email or DM in Slack.

@GiantCrocodile

This comment has been minimized.

Copy link
Author

commented Sep 5, 2019

It's okay; just don't publish it public online due to possible metadata included.

@afbora

This comment has been minimized.

Copy link
Contributor

commented Sep 7, 2019

@bastianallgeier You can send the files.

@bastianallgeier

This comment has been minimized.

Copy link
Contributor

commented Sep 9, 2019

@GiantCrocodile @afbora awesome! I just sent the file. Please give it a try on your machine. Meanwhile my thought was that it could also be a browser issue. What kind of browser do you use @GiantCrocodile?

@afbora

This comment has been minimized.

Copy link
Contributor

commented Sep 9, 2019

I have tried so many tests on following combinations:

OS:

  1. Windows
  2. Unix

PHP:

  1. 7.1
  2. 7.2
  3. 7.3

Software:

  1. EasyPHP
  2. Wampserver
  3. XAMPP

Browser:

  1. Chrome
  2. Firefox

It worked in all except XAMPP.
I found the reason it doesn't work at XAMPP (at least on my system).
Panel was giving a Bad Request error like you on XAMPP get because upload_max_filesize limit is 2MB (this is default PHP limit on first installation) and your file is 2.68MB.
I've increased the limit and it's working right now, with all tests.

@bastianallgeier

This comment has been minimized.

Copy link
Contributor

commented Sep 9, 2019

Thank you so much to @afbora! I should have thought about the upload limit.

I think it's not really a bug then, but we should create a new ticket to fix the error message in such cases when the file size is bigger than the upload limit.

@bastianallgeier

This comment has been minimized.

Copy link
Contributor

commented Sep 9, 2019

We decided to close this and use @afbora's new ticket instead to improve the error message.

@GiantCrocodile

This comment has been minimized.

Copy link
Author

commented Sep 9, 2019

It's right that I didn't check the max upload file size. Maybe that was the issue; it wasn't obvious to me in that case (although I'm not sure if I wouldn't have gotten a better PHP error message from PHP core because I checked the log and there was nothing useful.)

I'm using latest Firefox.

Thanks for your effort guys!

@bastianallgeier

This comment has been minimized.

Copy link
Contributor

commented Sep 9, 2019

@afbora has already created a PR and I took it a bit further. You will now get told that the php.ini Setting needs to be adjusted.

@GiantCrocodile

This comment has been minimized.

Copy link
Author

commented Sep 9, 2019

When you have merged your PR, I will test it again with my local setup (may take 1 or 2 days on my side due to work load from other projects). I hope it's fixed, although I'm sorry then for the caused to find the root cause of this issue.

@bastianallgeier

This comment has been minimized.

Copy link
Contributor

commented Sep 10, 2019

The PR is now merged on the develop branch.

@GiantCrocodile

This comment has been minimized.

Copy link
Author

commented Sep 10, 2019

A proper error is thrown: The issue was the max upload size in the PHP ini and after adjusting it, the error message was gone. Upload of all files worked!

@GiantCrocodile

This comment has been minimized.

Copy link
Author

commented Sep 10, 2019

@bastianallgeier Just noticed that the original, nothing-saying message occurs if you upload a 42 MB zip file. Is it due to being a forbidden file extension? If yes, can we get a proper message for that too?

@bastianallgeier

This comment has been minimized.

Copy link
Contributor

commented Sep 11, 2019

@GiantCrocodile you are probably running in the second related setting, which is the post_max_size. Unfortunately this is not included in the PHP error codes on failed uploads. I wonder if we can even catch this at all.

@afbora

This comment has been minimized.

Copy link
Contributor

commented Sep 11, 2019

@GiantCrocodile post_max_size must be greater than or equal to upload_max_filesize

I searched about catching post_max_size error and found three solutions:

1. Solution

We can partially catch it with $_SERVER['CONTENT_LENGTH']

if (isset($_SERVER['CONTENT_LENGTH'])) {
    $contentLength = (int) $_SERVER['CONTENT_LENGTH'];
    $postMaxSize = 1024 * 1024 * (int) ini_get('post_max_size');
    
    if($contentLength > $postMaxSize) {
        throw new Exception('The uploaded file exceeds the post_max_size directive in php.ini');
    }
}

2. Solution

If post is greater than post_max_size set in php.ini, $_FILES and $_POST will return empty.

3. Solution

If we will use second solution, we already check files is empty.

https://github.com/getkirby/kirby/blob/develop/src/Api/Api.php#L692-L694

So we need compare post_max_size and upload_max_filesize vars to throw right exception.

if (empty($files) === true) {
    $postMaxSize = 1024 * 1024 * (int) ini_get('post_max_size');
    $uploadMaxFileSize = 1024 * 1024 * (int) ini_get('upload_max_filesize');
    
    if($postMaxSize < $uploadMaxFileSize) {
        throw new Exception('The uploaded file exceeds the post_max_size directive in php.ini');
    } else {
        throw new Exception(t('upload.error.noFiles'));   
    }
}
@lukasbestle

This comment has been minimized.

Copy link
Contributor

commented Sep 12, 2019

I like the third solution as it catches the configuration issue pretty reliably.

@bastianallgeier

This comment has been minimized.

Copy link
Contributor

commented Sep 13, 2019

@afbora @lukasbestle Number 3 looks perfect. I just created a PR with it

bastianallgeier added a commit that referenced this issue Sep 13, 2019
bastianallgeier added a commit that referenced this issue Sep 13, 2019
@bastianallgeier

This comment has been minimized.

Copy link
Contributor

commented Sep 13, 2019

afbora added a commit to afbora/kirby that referenced this issue Sep 13, 2019
afbora added a commit to afbora/kirby that referenced this issue Sep 13, 2019
afbora added a commit to afbora/kirby that referenced this issue Sep 13, 2019
afbora added a commit to afbora/kirby that referenced this issue Sep 13, 2019
afbora added a commit to afbora/kirby that referenced this issue Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
5 participants
You can’t perform that action at this time.