如何将上传路径更改为 public_html 而不是 public laravel
How to change upload path to public_html instead of public laravel
我使用 laravel 背包并尝试上传图像。在当地工作。但在服务器中图像上传到 public,并没有显示在站点中我尝试更改磁盘和文件系统但没有任何改变
//型号
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;
}
}
//文件系统
'public' => [
'driver' => 'local',
'root' => public_path(),
'visibility' => 'public',
],
那么,在您的 public 数组中,根设置为 public_path()
,这是您的 public
文件夹的路径。如果你想改变它,你应该将你的配置设置为:
'public' => [
'driver' => 'local',
'root' => base_path('public_html'),
'visibility' => 'public',
],
我使用 laravel 背包并尝试上传图像。在当地工作。但在服务器中图像上传到 public,并没有显示在站点中我尝试更改磁盘和文件系统但没有任何改变
//型号
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;
}
}
//文件系统
'public' => [
'driver' => 'local',
'root' => public_path(),
'visibility' => 'public',
],
那么,在您的 public 数组中,根设置为 public_path()
,这是您的 public
文件夹的路径。如果你想改变它,你应该将你的配置设置为:
'public' => [
'driver' => 'local',
'root' => base_path('public_html'),
'visibility' => 'public',
],