Php 上传图像未保存在服务器Laravel 5.8上的目录中

Php 上传图像未保存在服务器Laravel 5.8上的目录中,php,laravel,laravel-5,Php,Laravel,Laravel 5,我部署了我的网站,我上传的图片有一个bug,这个图片不能保存在目录中 我的目录位于名为files的文件夹上的public\u html 在localhost上没有问题,但在我部署它之后,我就有了问题 本地主机上的控制器(没有类似问题) 此图像“名称”已保存在DB上,但此文件未保存,是否有人可以更正我的代码?如果文件文件夹位于项目的根路径中,而不在Laravel安装的公用文件夹中,则需要使用帮助程序而不是公用路径帮助程序来移动文件 $file->move(base_path('files')

我部署了我的网站,我上传的图片有一个bug,这个图片不能保存在目录中

我的目录位于名为files的文件夹上的
public\u html

在localhost上没有问题,但在我部署它之后,我就有了问题

本地主机上的控制器(没有类似问题)


此图像“名称”已保存在DB上,但此文件未保存,是否有人可以更正我的代码?

如果
文件
文件夹位于项目的根路径中,而不在Laravel安装的
公用文件夹中,则需要使用帮助程序而不是
公用路径
帮助程序来移动文件

$file->move(base_path('files'), $name);

如果
文件
文件夹位于项目的根路径中,而不在Laravel安装的
公用
文件夹中,则需要使用帮助程序而不是
公用路径
帮助程序来移动文件

$file->move(base_path('files'), $name);
试试这个代码

if ($request->hasfile('image')) {
       $file = $request->file('image');
       $name = $file->getClientOriginalName();
       $imagePath = $file->storeAs('/files/' . $name . '', 'public');
}
如果未链接,请不要忘记运行
php artisan storage:link

试试这段代码

if ($request->hasfile('image')) {
       $file = $request->file('image');
       $name = $file->getClientOriginalName();
       $imagePath = $file->storeAs('/files/' . $name . '', 'public');
}
如果未链接,请不要忘记运行
php artisan storage:link

替换您的代码

public function store6(Request $request)
{
    $this->validate($request, [
           //your validation code
    ]);

    if ($request->image != ''){   
        $path = 'files/';
        $file = $request->file('image');
        $name=$file->getClientOriginalName();
        $file->move($path, $name);  
        $data = $name;  
    }

    $user = new pemeliharaan;
    $id = Auth::user()->id;

    $user->user_id = $id;
    $user->alat_id = $request->alat_id;
    $user->pertanyaan =json_encode($request->except
    (['_token','name','alat_id','status','catatan','image']));
    $user->catatan = $request->catatan;
    $user->image=$data;
    $user->status = $request->status;


    $user->save();
  // dd($user);

    return redirect('user/show6')->with('success', 'Data Telah Terinput');    
}
替换您的代码

public function store6(Request $request)
{
    $this->validate($request, [
           //your validation code
    ]);

    if ($request->image != ''){   
        $path = 'files/';
        $file = $request->file('image');
        $name=$file->getClientOriginalName();
        $file->move($path, $name);  
        $data = $name;  
    }

    $user = new pemeliharaan;
    $id = Auth::user()->id;

    $user->user_id = $id;
    $user->alat_id = $request->alat_id;
    $user->pertanyaan =json_encode($request->except
    (['_token','name','alat_id','status','catatan','image']));
    $user->catatan = $request->catatan;
    $user->image=$data;
    $user->status = $request->status;


    $user->save();
  // dd($user);

    return redirect('user/show6')->with('success', 'Data Telah Terinput');    
}


您是否检查了文件文件夹是否存在?我检查了此文件夹,找到了它,但我尝试上载,此图像无法保存,我认为此上存在此问题。$file->move(public_path()。/files/,$name);您的
files
文件夹是否位于目录
public\u html
public\u html/public
?在public\u html/files/image.pngi上删除了文件夹public,因为下面是关于部署此laravel网站的教程。您是否检查了files文件夹是否存在?我检查了此文件夹,找到了它,但我尝试上载,此图像无法保存,我认为此问题存在。$file->move(public_path()。/files/,$name);您的
files
文件夹是否位于目录
public\u html
public\u html/public
?在public\u html/files/image.pngi上删除了文件夹public,因为下面关于部署此laravel网站的教程不起作用,先生,,如果我们删除了此基本路径或公共路径,该怎么办?因此,通常在项目中,您将在
public/storage
中创建指向
storage/app/public
目录的符号链接。这样事情就不会搞混了。你的
public
文件夹现在命名如何?您刚才是否将其重命名为
public\u html
?你的目录结构怎么样?我现在没有公用文件夹,我把它删除了。因为我按照教程删除了这个,所以在我的文件夹中是public_html/files/image.png这个文件像css,bower_组件在public_html/css/blablablabla.cssdidnt work先生,如果我们删除这个基本路径或public_路径怎么办?所以,通常在项目中,您将在
public/storage
中创建指向
storage/app/public
目录的符号链接。这样事情就不会搞混了。你的
public
文件夹现在命名如何?您刚才是否将其重命名为
public\u html
?你的目录结构怎么样?我现在没有公用文件夹,我把它删除了。因为我按照教程删除了这个,所以在我的文件夹中是public_html/files/image.png这个文件像css,bower_组件在public_html/css/blablabla.csin Cpanel中您必须创建符号链接
ln-s/path/to/laravel/storage/app/public/path/to/public/storage
这里建议另一种简单的方法:如何运行它?此符号链接尝试我建议的简单方法我运行此存储链接,但没有解决此问题。在Cpanel中,您必须创建符号链接
ln-s/path/to/laravel/storage/app/public/path/to/public/storage
此处建议另一种简单方法:如何运行此链接?此符号链接尝试我建议的简单方法我运行此存储链接,但没有解决此问题