dptt66700 2017-09-04 04:53
浏览 21

如何将图像上传到laravel上的不同项目?

I have two project or url

First url like this :

http://myshop.dev/

Second url like this :

http://backend.myshop.dev/

If the second url, I upload image it will save the image file here :

http://myshop.dev/img/image1.jpg

Both projects use the same database

My code to upload image on the second project like this :

public function __construct(...)
{
    ...
    $this->path  = './img';
}
...
public function store(...) {
    ...
    $filename = Input::file('photo')->getClientOriginalName();
    ...
    Input::file('photo')->move($this->path, $filename);
    ...
}

It works

If I upload image it will save the image in backend-myshop\public\img

But, I want to uploaded image not saved there. But in my first project

So, I want the image file saved here : myshop\public\img

How can I do it?

  • 写回答

1条回答 默认 最新

  • dtoqa66028 2017-09-04 06:06
    关注

    Hi after uploading copy them from backend-myshop\public\img to myshop\public\img you can use this storage copy method

    public function store(...) {
        ...
        $filename = Input::file('photo')->getClientOriginalName();
        ...
        Input::file('photo')->move($this->path, $filename);
    
        Storage::copy('backend-myshop/public/img/'.$filename, 'myshop/public/img/'.$filename);
        ...
    }
    

    hope this will solve your problem

    评论

报告相同问题?