How can I upload image to different project on the laravel?

六眼飞鱼酱① 提交于 2019-12-25 18:12:57

问题


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



来源:https://stackoverflow.com/questions/46030452/how-can-i-upload-image-to-different-project-on-the-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!