vendredi 29 septembre 2017

Laravel Upload image by excel

Hello friends i want to upload students data by excel in laravel with laravel excel plugin and i want to uploade image with excel file (By local path or other) Please suggest me solution for this

i create a function which upload file on my local server but not working on server

$excel = Excel::load(Input::file('file'))->get();
        foreach($excel as $exc) {
            $data = $exc->all();
            $data['class_id'] = $id;
            $data['school_id'] = $class->school_id;
            if ($student = Student::firstOrCreate($data)) {
                if (File::exists($exc->image)) {
                    $destinationPath = 'uploads/schools/' . $class->school_id . '/' . $class->id . '/' . $student->id . '/'; // upload path
                    if (!file_exists($destinationPath)) {
                        mkdir($destinationPath, 0755, true);
                    }
                    $file  = file_get_contents($exc->image);
                    $fileName = str_slug(Carbon::now()->toDayDateTimeString()) . rand(11111, 99999) . '.jpg'; // renameing image
                    if(file_put_contents($destinationPath.$fileName,$file)) {
                        $student->image = $destinationPath . $fileName;
                        $student->update();
                    }
                }
            }
        }



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2xOHiDY
via IFTTT

Aucun commentaire:

Enregistrer un commentaire