托管 Laravel 不存储图像

hosted Laravel not storing images

我在 CPanel 中托管了一个 Laravel 项目,它是 运行 但是当我上传图像时,它应该存储在 public 文件夹中,例如 ("public_path()/posts/theactualimage.jpeg").
图片路径存储在数据库中,但实际上根本没有存储真实图像

在我的本地机器上一切正常,但在托管机器上却不是这样

我不知道有没有我应该做的配置...

这是文件夹的结构

./
|    public_html
|    |    posts
|    |    index.php 
|    |    some other files
|
|    myapp
|    |    all the other files controllers views ...

这里是存储图片的函数

public function uploadImage($location, $imageName){
    $name = $imageName->getClientOriginalName();
    $imageName->move(public_path().'/'.$location, date('ymdgis').$name);
    return date('ymdgis').$name;
}

我没有使用 link 存储
谢谢你的帮助

您的函数缺少处理请求的关键要求。您没有在函数上传图片中收到任何请求。您需要在您的函数中接收一个请求,以便您可以进一步处理该请求。下面是一个示例代码,以便您更好地理解。

   /**
     * Storing an Image in public folder.
     *
     * @return \Illuminate\Http\Response
     */
    public function uploadImage(Request $request, $location, $imageName)
    {
        $request->validate([
            'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
        ]);
    
        $imageName = time().'.'.$request->image->extension();  
     
        $request->image->move(public_path('images'), $imageName);
  
        /* Store $imageName name in DATABASE from HERE if you want.  */
    
        return back()
            ->with('success','You have successfully upload image.')
            ->with('image',$imageName); 
    }
}

将图像存储在存储文件夹中

$request->image->storeAs('images', $imageName); // storage/app/images/file.png

将图像存储在 Public 文件夹中

$request->image->move(public_path('images'), $imageName); // public/images/file.png

在 S3 中存储图像

$request->image->storeAs('images', $imageName, 's3');