Answer the question
In order to leave comments, you need to log in
How to import text and pictures through PHPExcel Yii2?
I'm trying to parse text and images from an excel file in yii2 using phpexcell.
Cells with text are parsed perfectly, I can’t figure out how to push pictures into the database.
controller------
public function actionImport()
{
$modelImport = new \yii\base\DynamicModel([
'fileImport'=>'File Import',
]);
$modelImport->addRule(['fileImport'],'required');
$modelImport->addRule(['fileImport'],'file',['extensions'=>'ods,xls,xlsx'],['maxSize'=>1024*1024]);
if(Yii::$app->request->post()){
$modelImport->fileImport = \yii\web\UploadedFile::
if($modelImport->fileImport && $modelImport->validate()){
$inputFileType = \PHPExcel_IOFactory::identify($modelImport->fileImport->tempName);
$objReader = \PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($modelImport->fileImport->tempName);
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
$baseRow = 2;
while(!empty($sheetData[$baseRow]['A'])){
$model = new \app\models\Exel;
$model->Brend = (string)$sheetData[$baseRow]['A'];
$model->
$model->Image = (string)$sheetData[$baseRow]['C'];
$model->save();
$baseRow++;
Model----
public static function tableName()
{
return 'exel';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['Brend'], 'string'],
[['Sezon'], 'string'],
[['Image'], 'string '],
Poke your nose on how to render a picture and transfer it to the model for saving in the database, the column with pictures is set to blob in the database
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question