save in public folder laravel

1

How can I save documents in the public_html folder on my server?

I'm trying to save images but I can not get it, in my localhost it works fine, I attach my code:

          if($request->hasFile('img')){
            $file = $request->file('img');
            $name = $file->getClientOriginalName();
            $path = public_path() .'\img\controles';        
            $file->move($path,$name);
          } 
           dd($path) =C:\xampp\htdocs\login\public\img\controles

the structure of my project in local is like this

  • login
    • app
    • public
      • img
        • controls

in local I have no problems, everything works fine, I have the problem when I migrate it to the server, here is the structure of the project

  • login
    • app
    • public_html
      • css, js
      • img
        • controls

this is my code (the same as above, just change the 'path')

          if($request->hasFile('img')){
            $file = $request->file('img');
            $name = $file->getClientOriginalName();
            $path = public_path() .'\img\controles';        
            $file->move($path,$name);
          } 
           dd($path) = /home/onelap/login/public/img/controles

then the problem is generated in the '$ path', I can not get it to point to public_html / img / controls. PS: I tried with the method '$ request-> file (' img ') -> store (' public ')' but it only works on localhost and not on the server.

    
asked by Renato 08.10.2017 в 09:13
source

1 answer

1

One of the simplest solutions is to edit the public / index.php file to modify the variable of the public route:

After the line: $app = require_once __DIR__.'/../bootstrap/app.php';

Add the following code:

$app->bind('path.public', function() {
    return __DIR__;
});
    
answered by 08.10.2017 / 23:51
source