I have custom table with some fields including the image.
Now I want to import the data from CSV to custom table with the image.
Fields are like first_name, last_name, image.
I have done import for the text fields but need some idea regarding image upload.
In the image column I will pass the name of image. When import I need to import the image to the specific folder from given path on the site.
For example, I will upload images by FTP to pub/media/upload_images add the image name in the CSV when I import CSV it will take image from pub/media/upload_images and upload to employee_images folder.
$employeeData = [];
$tableName = $connection->getTableName('employee_data');
foreach ($csvData as $rowData) {
$employeeData[] = [
"first_name" => $rowData['first_name'],
"last_name" => $rowData['last_name'],
"image" => $rowData['image']
];
}
if (count($employeeData)) {
$connection->insertMultiple($tableName, $employeeData);
}