Laravel由excel上传图片

你好朋友,我想上传学生数据通过拉拉维尔excel与laravel excel插件,我想上传excel文件的图像(通过本地path或其他)请build议我解决这个问题

我创build了一个函数,在我的本地服务器上传文件,但不在服务器上工作

$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(); } } } } 

 $objphpexcel = PHPExcel_IOFactory::load("MyExcelFile.xls"); foreach ($objphpexcel ->getSheetByName("My Sheet1")->getDrawingCollection() as $drawing) { if ($drawing instanceof PHPExcel_Worksheet_MemoryDrawing) { ob_start(); call_user_func( $drawing->getRenderingFunction(), $drawing->getImageResource() ); $imageContents = ob_get_contents(); ob_end_clean(); $cellID = $drawing->getCoordinates(); // .... do your save here } } 

希望对你有帮助