[英]Laravel saved file/image in shared hosting got wrong directory
I have a function to upload files.我有一个 function 来上传文件。 on Localhost it's not having an error.在 Localhost 上没有错误。 but after I deploy on shared hosting, its have a problem.但是在我部署在共享主机上之后,它就出现了问题。 If localhost, I'm not moving some folder, but on "tutorial" shared hosting, I need to make 2 folders.如果是本地主机,我不会移动一些文件夹,但在“教程”共享主机上,我需要创建 2 个文件夹。 Laravel and public . Laravel和公共. this Laravel folder is all file on project Laravel without public这个Laravel文件夹是项目Laravel上的所有文件,没有公共
It's my schema on my shared hosting这是我在共享主机上的架构
(/home/sippausr) (/home/sippausr)
etc ETC
Laravel -> Laravel ->
app应用程序
bootstrap引导程序
config配置
database数据库
public_html public_html
resources资源
routes路线
storage贮存
tests测试
vendor小贩
logs日志
mail邮件
public_ftp public_ftp
public_html -> public_html ->
css css
files (not on here, i need to save here)文件(不在此处,我需要在此处保存)
home家
images图片
js js
kalibrasi卡利布拉西
public上市
sop肥皂
theme主题
And I have a function to upload a file and saved this file to directory files on public_html like this我有一个 function 来上传文件并将这个文件保存到public_html上的目录文件中,如下所示
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');
}
But, this file not saved at public_html/files
,但是,这个文件没有保存在public_html/files
,
This file saved in the Laravel folder, on public_html ( you can see at schema).此文件保存在public_html上的 Laravel 文件夹中(您可以在架构中看到)。 Can someone help me?有人能帮我吗?
Use the below code to save your file to your files
directory in your public
folder.使用以下代码将文件保存到public
中的files
目录中。
use Illuminate\Support\Facades\Storage;
class YourClassName implements Contract {
public function store6(Request $request) {
$this->validate($request, [
]);
if($request->hasfile('image')) {
$file = $request->file('image');
$name=$file->getClientOriginalName();
Storage::putFileAs('public/files', $file, $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();
return redirect('user/show6')->with('success', 'Data Telah Terinput');
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.