How can I upload image to different project on the

2019-08-26 06:26发布

问题:

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:

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