Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Upload error
  • Hello everyone !

    Today I have a really weird problem with \Upload class.
    I have a REST controller in subdirectory that receive a post request from client in AJAX and in my app others REST controller do this and they work properly. I get this error :


    ErrorException [ Fatal Error ]:
    Call to a member function getAllFiles() on a non-object

    COREPATH/classes/upload.php @ line 296

    291     * @param    array    $config
    292     * @return    void
    293     */
    294    public static function process($config = array())
    295    {
    296        foreach (static::$upload->getAllFiles() as $file)
    297        {
    298            $file->setConfig($config);
    299            $file->validate();
    300        }
    301    }


    COREPATH/bootstrap.php @ line 75

    If someone already met this problem I will be very happy to listen his solution ;) !

    NB: Error appear on process static method
  • Did you check the app log? Any exceptions in there?

    This can only happen if static::$upload isn't set. It is set when the class loads, which throws an exception if it can't be set. You can double check using the console:

    > php oil console

    and then type the statement: 

  • Hello Harro !
    The only error that appear in logs is the following :

    ERROR - 2017-12-20 07:35:08 --> Fatal Error - Call to a member function getAllFiles() on a non-object in /appli/projects/webfinance/apache_2.4/htdocs/webfinance/core/classes/upload.php on line 296

    For company silly reasons I can't test console...
    To temporary fix this issue I use the classic php way but I really want to use FuelPHP tools and I don't understand why this time it doesn't work.

    Thanks for your time ;)
  • Then you'll have to debug to see why the _init() method in the Upload class doesn't create an Upload instance in static::$upload.

    You do have the Upload composer package installed? 
  • Ok it's strange... I added logs output in _init upload's method but no output in log file !

    I check for composer package and upload is installed, I use it in other controller in the same app and it works...

  • Another class with the same name?
  • No class with the same name :/...
    Today I'm going to test in another module i it works !
  • Definitely weird! 

    The only thing I can think of is that the class isn't loaded by Fuel's autoloader, but by some other means, as the _init() method is Fuel's way to introduce a constuctor for static classes. Obviously, other loading methods won't call _init().
  • I test in another controller today and it works as expected...
    I think that I'm going to use the regular php way to do this in the concerned controller and use Upload in others ;) ! Sorry but I don't have the time to investigate :/...

    Thanks for your time Harro :) !
  • That failing controller isn't called Upload by any chance? So that it could be a bug in the autoloader?

  • Hello Harro and sorry it's been a long time but I was in vacations...
    No it is not, it is called post_globalImport :/
    And the class is called SubDir_Files (in Controller subnamespace of a module's namespace, sorry if it's not clear enough I'm not English.. :/).

    I have this problem only in this class, I'm wondering about the fact that it's located in a subdirectory in a module's controller folder, but I follow naming convention as mentioned in the documentation.

    Know I have to write few more upload methods in this controller and they doesn't work at all as "expected". It's weird !

    EDIT 1: I have the same issue with File class so I think that it's with all classes ! To fix it I just call _init method before call File static methods... it works. I haven't test with Upload class but it should work too.
  • I would still like to know why the Autoloader doesn't call the _init method. 

    You haven't messed with other autoloaders by any chance, like composers one? Fuel classes aren't compatible with it, Fuel's autoloader must be the first autoloader in line.

    If this would be a general problem, every Fuel user would be all over this forum. 

    So it must be something local.

    The init method is called here:, perhaps you can add some logging to the class to see where it goes wrong? I can't reproduce it, and I want to be absulutely sure it is not a race condition in the framework.
  • Hello Harro !
    I never modify fuel autoloader or app bootstrap, but the problem append only in one controller, this controller is located in a module like this :

        - classes:
            - controller:
                    - files.php (class name => Subfolder_Files extends \Controller_Rest)

    If I have some time to dig in it today then I will try to log some info to try to find something ;) !

    EDIT 1: I begin to work on another part of my module that is isolated in another subfolder of the module's controller folder. This time I try to use namespace Module\Controller\Subfolder with class name "Classname" instead of Module\Controller with class name "Subfolder_Classname".
    This time autoloader seems to work perfectly... weird.
  • Defined and namespaced correctly? Fuel supports three ways of defining your controller class:

    namespace Module;
    class Controller_Subfolder_Files extends \Controller_Rest {}


    namespace Module\Controller;
    class Subfolder_Files extends \Controller_Rest {}


    namespace Module\Controller\Subfolder;
    class Files extends \Controller_Rest {}

    Any other definition leads to misery... ;-)

    Options 1 and 3 are preferred, and if you want to use option 2 or 3 (controller namespacing), you need to change the config setting "controller_prefix" from 'Controller_' to 'Controller\\' in your app's config.php file. So you can't mix options 1 and 2 or 3 in your app.
  • Yes I read documentation on this topic again and again but I do it correctly, So it seems that there is a strange behavior with option 2... Option 3 solved my problem but the second should work too...

    Of course I setup "controller_prefix" in config file ;) !
    I suggeste to put "controller_prefix" to "Controller//" by default ! :)

    So option 2 is maybe "unstable" in modules ?
  • HarroHarro
    Accepted Answer
    Could be quite possible, I would have to test.

    All our apps use option 3. 

    Changing it do default however would cause all applications that use 1 or 2 to break as soon as they upgrade, so that is a change we don't do.
  • Cool Harro I have better understanding of your choice now ;) !
    Know I use option 3 and all is fine !
    Thanks for your help in investigations :) !

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion