vendredi 9 mars 2018

How to download and store and then upload drop box shared image in laravel?

I am trying to write a script to upload bulk product from excel sheet which contain product name, price and images. But the images are actually the dropbox image share link.

Now my question is how i can download those image from the drop box url, save them in my server storage and then upload the image url to my database?

Currently for the excel sheet reading i am using Maatwebsite/Laravel-Excel

Generic code for my upload is like this

public function productUpload(Request $request){
    if($request->hasFile('products')){
        $path= $request->file('products')->getRealPath();
        $data = Excel::load($path)->get();
        if($data->count()){
            foreach ($data as $key => $value) {

                //download the image create thumbain and  store to /images/product/thumbnail folder and get the link,
                $thumbnail = //here will be the path for the thumbnaul

                //Original image
                $original = ;
                $data['original']= $original;
                $data['thumbnail']=$thumbnail;
                $data['name']=$value->name;
                $data['price']= $value->price;
                Product::create($data);
            }

            return redirect()->back()->with('success','Product has been uploaded');
        }
    }
}

The image url that is in the excel sheet is like this one https://www.dropbox.com/s/x2tbsy49sraywvv/Ruby12.jpg?dl=0

This file has been removed at this point , but i hope this will give some idea. Can anyone please help me out. Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire