【问题标题】:Laravel server, upload to public_html rather than upload in project folder using laravel 8Laravel 服务器,上传到 public_html 而不是使用 laravel 8 上传到项目文件夹中
【发布时间】:2021-11-17 06:57:36
【问题描述】:

您好,我正在使用 Blue 共享主机,我一直在尝试在此站点上浏览以寻找答案,但对我来说没有任何效果,我想上传保存在 public_html 文件夹中的图像,而不是将其保存在项目文件夹中(我将项目文件夹分开并将所有公共文件放在 public_html 文件夹中)。但它返回到我的项目文件夹,而不是 public_html 一个。请帮助我如何解决这个谢谢。

控制器

if($request->has('image')){
            $imageName = Storage::disk('cms')->putFile('', $request->image);
            $home_slider->image  =   $imageName;
            $home_slider->save();
        }

文件系统.php

'cms' => [
            'driver' => 'local',
            'root' => public_path('uploads'),
            'url' => env('APP_URL').'uploads',
            'visibility' => 'public',
        ],

【问题讨论】:

    标签: laravel


    【解决方案1】:

    也许你可以尝试改变:

    $imageName = Storage::disk('cms')->putFile('', $request->image);
    

    收件人:

    $imageName = Storage::disk('local')->putFile('uploads', $request->image);
    

    假设public_html下你要上传图片的文件夹名为uploads

    【讨论】:

      【解决方案2】:

      我假设您在 public_html 下有一个名为 uploads 的文件夹

      如果您不想要任何自定义图像名称。只需按原样存储文件即可。你可以这样做:-

                $imagename = $request->txtFile->store('uploads');  
                $imagename=str_replace('uploads/','',$imagename);
                $destinationPath = 'uploads';
                $file->move($destinationPath, $imagename);
      

      如果你想给自定义名称,那么你可以这样做:-

      例如:

                $random = Str::random(10);
                $timestamp=strtotime(date('H:i:s')).$random;
                $customfilename=$slug.'-logo-'.$timestamp.'.'.$fileextension;
                $imagename = $request->txtFile->storeAs('uploads',$customfilename);  
                $imagename=str_replace('uploads/','',$imagename);
                $destinationPath = 'uploads';
                $file->move($destinationPath, $imagename);
      

      【讨论】:

        猜你喜欢
        • 2020-09-03
        • 1970-01-01
        • 1970-01-01
        • 2022-11-20
        • 2014-03-31
        • 2016-05-29
        • 2021-05-02
        • 2021-04-10
        • 2021-12-17
        相关资源
        最近更新 更多