0
votes

i have a laravel project and its uploaded on a sharing host i have this code for moving uploaded file to folder : $request->file->move(public_path('images\banners'), $new_name);

my website is like : root/ laravel public_html

i just want to move uploaded file to public_html folder

public function register()
{
    //
    $this->app->bind('path.public', function() {
        return realpath(base_path().'/../public_html');
    });
}

i try this but its not working

2

2 Answers

0
votes

The laravel way is to use FlySystem. Open up config/filesystems.php and add a new entry for public_html.

'disks' => [

    'public_html' => [
        'driver' => 'local',
        'root'   =>  '/full/path/to/public_html', 
    ],
...

Then use it as Storage::disk('public_html')->put('filename', 'contents');. There are other methods on the docs on how to move or upload files to a specific storage here https://laravel.com/docs/5.8/filesystem.

Additionally, instead of specifying the fullpath you can use helper functions such as storage_path() or public_path() depending on where your directory is.

0
votes
    $file = $request->file('image');
    $extension = $file->getClientOriginalExtension(); // getting image extension
    $filename =time().'.'.$extension;
    $path = $file->move(public_path('uploads'), $filename);
    $newPath = explode('\public\\', $path);
    $filePath = end($newPath);