简体   繁体   English

如何在带有存储的主机中上传文件?

[英]How to upload a file in the host with storage?

I wanted to ask what is it like to upload to a host and save it?我想问一下上传到主机并保存是什么感觉? Of course in the storage folder当然在存储文件夹中

Why does this source of mine upload in localhost but not in Host?为什么我的这个来源上传到本地主机而不是主机?

But it does not upload at all in the host.但它根本不会在主机中上传。

public function store(Request $request)
{
    $path = $request->file('image') ?? null;
    if ($request->hasFile('image'))
    {
        $file = $request->file('image');
        $name = time();
        $extension = $file->getClientOriginalExtension();
        $fileName = $name . '.' . $extension;
        $path = $file->storeAs('images/aboutExhibitions', $fileName, 'public');
    }
    AboutExhibition::query()->create([
        'user_id' => auth()->id(),
        'title' => $request->title,
        'link' => $request->link,
        'image' => $path,
        'options' => $request->options,
        'body' => $request->body,
    ]);
    return redirect()->route('admin.aboutExhibitions.index');
}   

In the meantime, when I was inside the localhost, I executed the following command before.同时,当我在 localhost 中时,我之前执行了以下命令。

php artisan storage:link

Hope this will work.希望这会奏效。

                $image = $request->image;
                $image_name=uniqid().date('dmYhis');
                $ext=strtolower($image->getClientOriginalExtension());
                $image_full_name=$image_name.'.'.$ext;
                $image_url=$upload_path.$image_full_name;
                $success=$image->move($upload_path,$image_full_name);
                $data = array();
                $data['image']=$image_url;
                $store = Custom::create($data);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM