GithubHelp home page GithubHelp logo

Bug about get_file_size about laravel-console HOT 5 CLOSED

darsain avatar darsain commented on September 2, 2024
Bug about get_file_size

from laravel-console.

Comments (5)

darsain avatar darsain commented on September 2, 2024

I'm not getting this error (PHP 5.4.7), but 0 is a valid file size, so this is more of a Laravel's get_file_size helper bug, and should be reported there.

But, can you give me an output of this line:

echo @round(0 / pow(1024, floor(log(0, 1024))), 2);

There is a division by zero, but called with @ should return 0 anyways (as it does for me).

from laravel-console.

markwu avatar markwu commented on September 2, 2024

It return 0 for me. Than, that's interesting. We have the same result, how come I get error exception.

Here comes the error exception:

Unhandled Exception
Message:

Undefined offset: -9223372036854775808

Location:

/home/www/sites/myproject/laravel/helpers.php on line 597

Stack Trace:

0 /home/www/sites/myproject/laravel/laravel.php(40): Laravel\Error::native(8, 'Undefined offse...', '/home/www/sites...', 597)
1 /home/www/sites/myproject/laravel/helpers.php(597): Laravel{closure}(8, 'Undefined offse...', '/home/www/sites...', 597, Array)
2 /home/www/sites/myproject/bundles/console/models/console.php(34): get_file_size(0)
3 /home/www/sites/myproject/bundles/console/controllers/console.php(55): Console::execute('')
4 [internal function]: Console_Console_Controller->post_execute()
5 /home/www/sites/myproject/laravel/routing/controller.php(325): call_user_func_array(Array, Array)
6 /home/www/sites/myprojectw/laravel/routing/controller.php(285): Laravel\Routing\Controller->response('execute', Array)
7 /home/www/sites/myprojectw/laravel/routing/controller.php(165): Laravel\Routing\Controller->execute('execute', Array)
8 /home/www/sites/myproject/laravel/routing/route.php(153): Laravel\Routing\Controller::call('console::consol...', Array)
9 /home/www/sites/myproject/laravel/routing/route.php(124): Laravel\Routing\Route->response()
10 /home/www/sites/myproject/laravel/laravel.php(165): Laravel\Routing\Route->call()
11 /home/www/sites/myproject/public/index.php(34): require('/home/www/sites...')
12 {main}

from laravel-console.

markwu avatar markwu commented on September 2, 2024

Okay, I think I found the problem, the problem is $unit.

$units = array('Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB');
return @round($size / pow(1024, ($i = floor(log($size, 1024)))), 2).' '.$units[$i];

When set $size to 0, $i will be -INF (-9223372036854775808) in PHP 5.3.10.

So, $units[-INF] does not exist.

Why yours php accept $units[-INF], and mine doesn't?? No idea!

Can you kindly print your $i for me?

from laravel-console.

darsain avatar darsain commented on September 2, 2024

Should be OK for you now. I've replaced the Laravel's helper with custom function:

function nice_bytesize($size)
{
    $units = array('Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB');
    return @round($size / pow(1024, ($i = max(floor(log($size, 1024)), 0))), 2).' '.$units[$i];
}

from laravel-console.

markwu avatar markwu commented on September 2, 2024

Thanks!!

from laravel-console.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.