Laravel:如何将图像保存到公共(public)文件夹?

标签 laravel upload

我无法将用户图像上传到我的公共(public)文件夹。文件名生成正确,并将名称保存到我的数据库中,除了 iamge 本身拒绝保存到我的公共(public)文件夹中。我做错了什么?

  public function update_avatar(Request $request) {
  if($request->hasFile('avatar')) {

    $avatar = $request->file('avatar');
    $filename = time() . "." . $avatar->getClientOriginalExtension();

    Image::make($avatar)->resize(300,300)->save(public_path('/uploads/'.$filename)); ==> This is causing me errors

    user = Auth::user();
    $user->avatar = $filename;
    $user->save();

  }

最佳答案

The public disk is intended for files that are going to be publicly accessible. By default, the public disk uses the local driver and stores these files in storage/app/public. To make them accessible from the web, you should create a symbolic link from public/storage to storage/app/public. This convention will keep your publicly accessible files in one directory that can be easily shared across deployments.

To create the symbolic link, you may use the storage:link Artisan command:

php artisan storage:link

https://laravel.com/docs/5.5/filesystem

关于Laravel:如何将图像保存到公共(public)文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46710275/

相关文章:

php - laravel 5 将日期和时间插入数据库

mysql - 从mysql数据库获取数据

json - Vue-if 条件不起作用。 if-Else block 似乎被跳过

php - Laravel ajax catch 500 内部服务器错误

google-app-engine - 平台中立的 JSP Zip 文件上传 (Google App Engine/Tomcat)

java - 如何监控文件上传进度?

WCF 服务合约接收来自 ExtJs 前端的文件上传

php - Laravel:PDO 异常,即使已安装和测试驱动程序也找不到驱动程序

PHP上传文件Mysql失败

javascript - 使用 readAsDataURL() 进行图像预览