Magento 2 add simple product programmatically

just create a file like upload.php and run from root directory.

<?php
use \Magento\Framework\App\Bootstrap;
include(‘app/bootstrap.php’);

$bootstraps = Bootstrap::create(BP, $_SERVER);
$object_Manager = $bootstraps->getObjectManager();

$app_state = $object_Manager->get(‘\Magento\Framework\App\State’);
$app_state->setAreaCode(‘frontend’);

$set_product = $object_Manager->create(‘\Magento\Catalog\Model\Product’);

try{
$set_product->setWebsiteIds(array(1));
$set_product->setAttributeSetId(4);
$set_product->setTypeId(‘simple’);
$set_product->setCreatedAt(strtotime(‘now’));
$set_product->setName(‘BD product simple product’);
$set_product->setSku(‘bd-pro-simple’);
$set_product->setWeight(1.0000);
$set_product->setStatus(1);
$category_id= array(4,5,6,7);
$set_product->setCategoryIds($category_id);
$set_product->setTaxClassId(0);
$set_product->setVisibility(4);
$set_product->setManufacturer(29);
$set_product->setColor(20);
$set_product->setPrice(1999);
$set_product->setCost(1800);
$set_product->setMsrpDisplayActualPriceType(1);
$set_product->setMetaTitle(‘BD product simple product’);
$set_product->setMetaKeyword(‘BD product simple product’);
$set_product->setMetaDescription(‘BD product simple product’);
$set_product->setDescription(‘This is a long description BD product simple product’);
$set_product->setShortDescription(‘This is a short description BD product simple product’);
$set_product->setStockData(
array(
‘use_config_manage_stock’ => 0,
‘manage_stock’ => 1,
‘min_sale_qty’ => 1,
‘max_sale_qty’ => 5,
‘is_in_stock’ => 1,
‘qty’ => 10
)
);

$set_product->save();

$get_product_id = $set_product->getId();
echo “Uploaded simple product id :: “.$get_product_id.”\n”;
}
catch(Exception $exception)
{
Mage::log($exception->getMessage());
}