Import Produktow z XLS

Wybierz plik XLS z produktami do importu:
50000000) { echo "Sorry, your file is too large."; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { // echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded."; $uploaded=true; } else { echo "Nie można wrzucić pliku!"; } } } else { echo 'nic@'; } if($uploaded==true){ /** Include path **/ set_include_path(get_include_path() . PATH_SEPARATOR . '/cards/'); /** PHPExcel_IOFactory */ include 'modules/EcmProducts/cards/PHPExcel/IOFactory.php'; $inputFileName =$target_file; echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory to identify the format
'; $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); $i = 0; $files=array(); foreach ($objPHPExcel->getActiveSheet()->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(); switch ($drawing->getMimeType()) { case PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_PNG : $extension = 'png'; break; case PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_GIF: $extension = 'gif'; break; case PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_JPEG : $extension = 'jpg'; break; } } else { $zipReader = fopen($drawing->getPath(),'r'); $imageContents = ''; while (!feof($zipReader)) { $imageContents .= fread($zipReader,1024); } fclose($zipReader); $extension = $drawing->getExtension(); } $path='modules/EcmProducts/cards/images/'; $myFileName ='00_Image_'.create_guid().++$i.'.'.$extension; $files[$i]['path']=$path.''.$myFileName; $files[$i]['name']=$myFileName; $myFileName=$path.$myFileName; file_put_contents($myFileName,$imageContents); } echo '
'; $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); if(count($sheetData)>1){ $i=1; foreach ($sheetData as $key=>$val){ if($key==1 || $val['A']=='')continue; echo "raz"; $p= new EcmProduct(); $p->name=$val["C"]; $p->code=$val["A"]; $p->efficiency=$val["B"]; $p->unit_id='3'; $p->vat_id='28079566-b825-e38f-9993-4ccc7b781de5'; if($val["E"]==1){ $p->product_picture=$files[$i]['name']; $i++; move_uploaded_file($files[$i]['path'],'modules/EcmProducts/upload/images/'.$files[$i]['name']); } $id=$p->save(); $db=$GLOBALS['db']; $db->query("insert into ecmprices_ecmproducts values ('".create_guid()."','44ac3ec1-d60f-195d-29d7-406defa32453','".$id."','".$val["D"]."')"); echo '"'.$id.'",'; } } // var_dump($sheetData); } ?>