2017-09-29 5 views
2

こんにちはiはlaravel ExcelのプラグインとlaravelでExcelでの学生のデータをアップロードしたいの友人と私は、Excelファイルに画像をuploadeたい は私にこのLaravelアップロード画像は、(ローカルパスまたは他のことで)

のためのソリューションを提案してください。

私は私のローカルサーバー上のアップロードファイルが、サーバ上で動作していない

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

は、このリンクをチェックするのに役立ちます願っ機能を作成します。https:// laracastsを.com/discuss/channels/laravel/insert-image-with-laravel-excel –

+0

ローカルマシンでサーバーにイメージをアップロードしたい –

答えて

0
$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 
    } 
} 

これはあなた

関連する問題