【问题标题】:Cannot see files in laravel on shared hosting在共享主机上看不到 laravel 中的文件
【发布时间】:2017-11-21 11:23:23
【问题描述】:

我有问题。我的 laravel 在共享主机上看不到图片。

我在 ~/domains/DOMAIN/public_html/APP 中有公共文件夹,在 ~/domains/DOMAIN/FILES 中有其余文件。

我的文件正在上传到 ~/domains/DOMAIN/FILES/storage/app/public/uploads/avatars

但在应用中我看不到这个。

这是上传代码:

public function addAvatar(Request $request) { $this->validate($request, [ 'file' => 'required', ]);

    $user = $this->model->getUserById(Auth::user()->id);

    $file = $request->file('file')->store('/public/uploads/avatars');

    $filename = $request->file('file')->hashName();

    $extension = pathinfo($file, PATHINFO_EXTENSION);

    if($extension == 'png' OR $extension == 'jpg' OR $extension == 'jpeg'){

        $file = UserData::avatar($request, $filename, $user->id);

        return view('user.settings', compact('user')); 
    }
    else
    {
        $file = unlink($request->file('file'));

        return view('user.settings.files', compact('user'))->with('message', 'nope');
    }
}

你能帮我做什么吗?

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    只需使用

    ->store('avatars') //and make it public
    Storage::put('file.jpg', $contents, 'public');
    

    Laravel File StorageDocu 中有一些如何处理上传和存储的示例

    如果您想收到它们:

    $contents = Storage::get('file.jpg'); 
    //or just the url: 
    $url = Storage::url('file1.jpg');
    

    【讨论】:

    • 那怎么显示呢?
    • 什么是 $contents 变量?
    猜你喜欢
    • 2018-09-04
    • 1970-01-01
    • 2020-01-16
    • 1970-01-01
    • 2017-04-12
    • 2019-10-25
    • 1970-01-01
    • 2018-06-21
    • 2020-02-07
    相关资源
    最近更新 更多