protected function saveImages($images) { if (count($images) > 0) { foreach ($images as $key => $url) { $image_entity = ProductImageModel::findOneByUrl($url); if (!$image_entity) { // save image to local HDD $filename = 'p_' . $this->product->id . '_i_' . $key . '.jpg'; $filepath = 'd:\\workspace\\newhtf\\data\\images\\' . $filename; $image_bin = file_get_contents($url); file_put_contents($filepath, $image_bin); // save image to DB if (file_exists($filepath)) { $image_entity = new ProductImage(); $image_entity->fromArray(['product_id' => $this->product->id, 'url' => $url, 'filename' => $filename]); $image_entity->save(); } } else { $image_entity->id; } } } }