Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "docker";
- $username = "docker";
- $password = "docker";
- try {
- $db = new PDO("mysql:host=$servername;dbname=docker", $username, $password);
- // set the PDO error mode to exception
- $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- echo "Connected successfully";
- }
- catch(PDOException $e)
- {
- echo "Connection failed: " . $e->getMessage();
- }
- $import_products = true;
- $import_products_to_categories = false;
- if ($import_products == true) {
- $handle = fopen('products.csv', "r");
- $rowno = 0;
- while (($data = fgetcsv($handle, 9000, ",")) !== FALSE) {
- $num = count($data);
- $rowno++;
- if($rowno == 1) {
- print_r($data);
- }
- if($rowno > 1) {
- $product_id = $data[0];
- $product_model = $data[1];
- $product_name = $data[2];
- $product_summary = $data[3];
- $product_description = $data[4];
- $product_url = $data[5];
- $manID = $data[6];
- $product_status = $data[7];
- $vatcode = $data[8];
- $RRPprice = $data[9];
- $minQTY = $data[10];
- $weight = $data[11];
- $meta_title = $data[12];
- $meta_decs = $data[13];
- $meta_keywords = $data[14];
- $visibility = $data[15];
- $createDate = $data[16];
- $lastModified = $data[17];
- $featured = $data[18];
- $promoted = $data[19];
- $quantity = $data[20];
- $ship_adj = $data[21];
- $custom1 = $data[22];
- $custom2 = $data[23];
- $custom3 = $data[24];
- $custom4 = $data[25];
- $custom5 = $data[26];
- $custom6 = $data[27];
- $custom7 = $data[28];
- $custom8 = $data[29];
- $custom9 = $data[30];
- $custom10 = $data[31];
- $customText1 = $data[32];
- $customText2 = $data[33];
- $customText3 = $data[34];
- $topTenRanking = $data[35];
- $shippingGroup = $data[36];
- $domain = 'http://www.tvandfilmsupplies.co.uk/';
- $prodPath = 'ecommerce/product/';
- $img_path = '/var/www/platform/public/images';
- $images = array();
- $imageSrc = getElementByIdAsString($domain . $prodPath . $product_url . '.aspx', 'ctl00_cphContent1_ctl00_ProductImageViewer1_imgFull');
- if ($imageSrc) {
- $name = basename($imageSrc);
- $image = $img_path . '/' . $name;
- $imageSave = file_put_contents($image, file_get_contents($domain . $imageSrc));
- if($imageSave) {
- // Update product image
- $imageUpdate = $db->prepare('UPDATE products SET products_image = :image_name WHERE products_id = :products_id');
- $imageUpdate->execute(array(':image_name' => $name, ':products_id' => $product_id));
- }
- }
- }
- }
- fclose($handle);
- }
- /**
- * Downloads a web page from $url, selects the the element by $id
- * and returns it's xml string representation.
- */
- function getElementByIdAsString($url, $id, $pretty = true) {
- $doc = new DOMDocument();
- @$doc->loadHTMLFile($url);
- if(!$doc) {
- throw new Exception("Failed to load $url");
- }
- // Obtain the element
- $element = $doc->getElementById($id);
- if(!$element) {
- throw new Exception("An element with id $id was not found");
- }
- if($pretty) {
- $doc->formatOutput = true;
- }
- $srcElement = $element->getAttribute('src');
- if(isset($srcElement)) {
- $srcElement = explode('?', $srcElement);
- return $srcElement[0];
- }
- return false;
- }
Add Comment
Please, Sign In to add comment