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

Error saving Bill with attachment #3098

Closed
feralhipichik opened this issue Nov 26, 2023 · 3 comments
Closed

Error saving Bill with attachment #3098

feralhipichik opened this issue Nov 26, 2023 · 3 comments
Labels
Milestone

Comments

@feralhipichik
Copy link

feralhipichik commented Nov 26, 2023

Akaunting version

3.0.16

PHP version

8.2

Operating system

Linux 4.18.0-425.19.2.lve.el7h.x86_64 x86_64

Steps to reproduce

Create a new Bill and add an attachment, or open a Bill with and attachment, then Save.

Expected result

Bill saves with attachment, takes me to Bill preview with option to add a payment

Actual result

500 Internal Server Error
Oops! Something went wrong
Go to dashboard
500

Additional comments

The Bill saves, with the attachment, but outputs this error. I enabled debugging and have included the error reported below

Relevant log output

TypeError
ViewException
ViewException
ViewException
ViewException
HTTP 500 Internal Server Error
Plank\Mediable\Helpers\File::readableSize(): Argument #1 ($bytes) must be of type int, string given, called in /home/******/public_html/***.biz/akaunting/vendor/plank/laravel-mediable/src/Media.php on line 308 (View: /home/******/public_html/***.biz/akaunting/resources/views/components/media/file.blade.php) (View: /home/******/public_html/***.biz/akaunting/resources/views/components/media/file.blade.php) (View: /home/******/public_html/***.biz/akaunting/resources/views/components/media/file.blade.php) (View: /home/******/public_html/***.biz/akaunting/resources/views/components/media/file.blade.php)
@cuneytsenturk
Copy link
Member

Hello,

This issue is the reason for your upload file size. This exception function ;

    /**
     * Calculate the file size in human readable byte notation.
     * @param  int $precision (_optional_) Number of decimal places to include.
     * @return string
     */
    public function readableSize(int $precision = 1): string
    {
        return File::readableSize($this->size, $precision);
    }

@feralhipichik
Copy link
Author

Thanks for that info... is it necessary or can it be commended out? Can I change it to something that won't cause an issue?

@cuneytsenturk
Copy link
Member

The error message indicates that there is an issue in the Plank\Mediable\Helpers\File::readableSize() method call in the Media.php file on line 308. The error specifies that the first argument passed to this method must be of type int, but a string is being provided.

To solve this issue, you need to make sure that the value passed as the first argument to File::readableSize() is an integer.

Here are some steps you can follow:

  1. Check the data type of the argument:
    Look at the code in Media.php on line 308 and check what value is being passed as the first argument to File::readableSize(). Ensure that it is an integer.

  2. Convert the argument to an integer if necessary:
    If the argument is a string, you may need to convert it to an integer before passing it to File::readableSize(). You can use the intval() function for this purpose.

    $bytes = intval($yourStringValue);

    Replace $yourStringValue with the actual variable or value that is being passed.

  3. Handle edge cases:
    Ensure that the value being passed to File::readableSize() is always a valid integer. If there are cases where it could be a string, make sure to handle those cases appropriately.

  4. Check for other instances of the method call:
    If the issue persists, check if there are other places in your codebase where File::readableSize() is called and review those calls to ensure that the first argument is always of type int.

Once you have made the necessary adjustments, the error should be resolved. Additionally, you may want to check the documentation or source code of the Plank\Mediable\Helpers\File class to understand the expected input types for the readableSize() method.

@cuneytsenturk cuneytsenturk added this to the 3.1.6 milestone Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants