如何将上传路径更改为public_html而不是public laravel

时间:2018-12-29 12:34:39

标签: laravel backpack-for-laravel

我使用laravel背包,我尝试上传图片。在当地工作。但在服务器中,该图像已上载到公共场所,但未在网站上显示,我尝试更改磁盘和文件系统,但未更改

//型号

 public function setPosterAttribute($value)
    {
        $attribute_name = "poster";
        $disk = "public";
        $destination_path = "uploads/products/posters";

        // if the image was erased
        if ($value==null) {
            // delete the image from disk
            \Storage::disk($disk)->delete($this->{$attribute_name});

            // set null in the database column
            $this->attributes[$attribute_name] = null;
        }

        // if a base64 was sent, store it in the db
        if (starts_with($value, 'data:image'))
        {
            // 0. Make the image
            $image = \Image::make($value);
            // 1. Generate a filename.
            $filename = md5($value.time()).'.jpg';
            // 2. Store the image on disk.
            \Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream());
            // 3. Save the path to the database
            $this->attributes[$attribute_name] = $destination_path.'/'.$filename;
        }
    }

// fileSystem

    'public' => [
        'driver' => 'local',
        'root' => public_path(),
        'visibility' => 'public',
    ],

1 个答案:

答案 0 :(得分:2)

好吧,在您的公共数组中,根目录设置为public_path(),这是您的public文件夹的路径。如果要更改此设置,则应将配置更改为以下内容:

'public' => [
    'driver' => 'local',
    'root' => base_path('public_html'),
    'visibility' => 'public',
],