wojtas26 Posted July 9, 2017 Share Posted July 9, 2017 <? require 'Medoo.php'; use Medoo\Medoo; global $db; try { $db = new Medoo([ 'database_type' => 'mysql', 'database_name' => 'prestashop', 'server' => 'localhost', 'username' => 'pma', 'password' => '', 'charset' => "utf8" ]);} catch (Exception $e){ echo $e->getMessage(); } $produkty=$db->select("psw_product_attribute", ["id_product","id_product_attribute","ean13","quantity"]); $atributy= $db->select("psw_product_attribute_combination", ["id_attribute","id_product_attribute"]); $atributy_size= $db->select("psw_attribute_lang", ["id_attribute","name"]); //file csv if(isset($_FILES['fileToUpload'])){ $target_dir = "uploads/"; $target_file = $target_dir . time() . basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); if(isset($_POST['submit'])){ // Check if image file is a actual image or fake image // Check if file already exists if (file_exists($target_file)) { echo "Sorry, file already exists."; $uploadOk = 0; } //Check file size if ($_FILES["fileToUpload"]["size"] > 50000000) { echo "Sorry, your file is too large."; $uploadOk = 0; } //Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded."; if (($handle = fopen($target_file, "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) { $ean = $data[4]; $id = $data[0]; $velikost= $data[1]; $pocet = $data[9]; // echo implode(' ', $data) .' <br>'; foreach ($produkty as $row_db) { if($id==$row_db['id_product']){ // echo "id " .$row_db['id_product']." ean ".$row_db['ean13']. " ks ". $row_db['quantity']." atribut " .$row_db['id_product_attribute']."<br>"; foreach($atributy as $val){ if($row_db['id_product_attribute']==$val['id_product_attribute']) // && $val['id_attribute']<=21) { foreach($atributy_size as $name) { if($val['id_attribute']==$name['id_attribute']) { $size=$name['name']; } } } // echo "id " .$val['id_attribute']." produkt atribute = ".$val['id_product_attribute']." velikost= ".$size." csv vel.= ".$velikost."<br>"; $id_product_attribute=$val['id_product_attribute']; if($velikost==$size){ $array = (isset($_POST['qua'])) ? ["ean13" => $ean, "quantity" => $pocet] : ["ean13" => $ean]; //$db->update("psw_product",$array,["id_product" => $id]); $db->update("psw_product_atribute",$array,["id_product_attribute" => $id_product_attribute]); echo "<pre>" ; // print_r(var_dump( $db->debug() )."<br>"); // print_r($array); echo "id " .$val['id_attribute']." produkt atribute = ".$val['id_product_attribute']." velikost= ".$size." csv vel.= ".$velikost." ean= ".$ean."<br>"; echo "</pre>" ; } } } }//end foreach } fclose($handle); } } else { echo "Sorry, there was an error uploading your file.<br>"; } //end else } // if everything is ok, try to upload file end }//end submit // NAHRANO }//end file csv ?> <!DOCTYPE html> <html> <head> <title>Konvertor</title> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <!-- Optional theme --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> <!-- Latest compiled and minified JavaScript --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> </head> <body> <form action="" method="POST" enctype="multipart/form-data"> <div class="form-group"> <label class="control-label">vyberte</label> <input id="input-1a" type="file" name="fileToUpload" class="file" data-show-preview="false"> </div> <div class="form-check"> <label class="form-check-label"> <input type="checkbox" name="qua" class="form-check-input"> Aktualizovat množství </label> </div> <button type="submit" name="submit" class="btn btn-primary">Nahrát</button> </form> </body> </html> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now