简体   繁体   中英

Laravel - You don't have permission to access /images/ on this server

I have a Laravel project uploaded to Heroku.

Everything works fine, except the functionality of uploading images . When I attempt to upload, it shows this,

" Forbidden You don't have permission to access /images/ on this server. "

Here is how my store() function looks,

public function store(Request $request)
{
    $this->validate($request, [
       'filename' => 'required',
       'filename.*' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048'
    ]);

    if ($request->hasFile('filename')) {
        foreach ($request->file('filename') as $image) {
            $name = $image->getClientOriginalName();
            $image->move(public_path() . '/images/', $name);
            $data[] = $name;
        }
    }

    return back()->with('success', 'Images uploaded successfully!');
}

This isn't resolving your issue per-se. But you will face that other issue later on.

You shouldn't upload files directly on Heroku's filesystem if you expect them to stick around. Heroku has an ephemeral filesystem . Each dyno is an independent container. Whenever your app is restarted, a new container is started, meaning anything stored on the filesystem is them permanently lost.

You should upload your files to a dedicated storage system such as Google Cloud, or Amazon S3. See https://devcenter.heroku.com/articles/s3-upload-php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM