我具有上传文件的功能。在Localhost上没有错误。但是当我在共享主机上部署后,它就出现了问题。 如果本地主机,我不移动某些文件夹,但在“教程”共享主机上,我需要制作2个文件夹。 laravel 和 public 。这个 laravel 文件夹是项目 laravel 上的所有文件,没有 public
将其架构显示在共享主机上
(/ home / sippausr)
等
laravel->
app
引导程序
config
数据库
public_html
资源
路线
存储
测试
供应商
日志
邮件
public_ftp
public_html->
css
文件(不在此处,我需要在此处保存)
家
图片
js
kalibrasi
公共
sop
主题
我有一个上传文件的功能,并像这样
将文件保存到 public_html 上的目录 files 上public function store6(Request $request)
{
$this->validate($request, [
]);
if($request->hasfile('image'))
{ $file = $request->file('image');
$name=$file->getClientOriginalName();
$file->move(public_path().'/files/', $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_html / files中,
此文件保存在 public_html 上的Laravel文件夹中(您可以在架构上看到)。有人可以帮我吗?
答案 0 :(得分:0)
如果我了解您要保存文件到Laravel目录之外,并且要使用Laravel级别目录中编写的“ public_path()”方法存储文件,则可能的解决方案是在.env文件中声明一个变量
PUBLIC_DIRECTORY="/var/www/public_html/" ##Path to your public_directory
并像这样修改您的代码:
if($request->hasfile('image')){
$file = $request->file('image');
$name=$file->getClientOriginalName();
$file->move(env('PUBLIC_DIRECTORY').'/files/', $name);
$data = $name;
}
希望我能对您有所帮助
答案 1 :(得分:0)
在公共目录中创建“文件”目录
授予文件目录权限
['japan']