halohalo
bnmbnmbnhjkhjkhjkhjktyutyutyuytutyutyutyhgjgjghjgjghjguytutyry
/
home
/
aramiyarkai
/
public_html
/
admin
/
Upload FileeE
HOME
<?php include 'dbc.php'; if($_POST['submit'] == "Save"){ $filePath = "price/"; $temporaryFile = $_FILES['files']['tmp_name']; //get the Temporary location of file $temporaryName = $_FILES['files']['name']; //get the name of file. $ext = strtolower(pathinfo($temporaryName, PATHINFO_EXTENSION)); $fileName = date("Y-m-d-h-i-s").rand().".".$ext; if($ext == "csv"){ if(move_uploaded_file($temporaryFile,$filePath.$fileName)){ //open uploaded csv file with read only mode $csvFile = fopen($filePath.$fileName, 'r'); //skip first line fgetcsv($csvFile); //parse data from csv file line by line while(($line = fgetcsv($csvFile)) !== FALSE){ $product_id = $line[0]; $cost_price = $line[1]; $selling_price = $line[2]; $mrp_price = $line[3]; mysqli_query($link,"update product_tbl set cost_price='$cost_price',mrp_price='$mrp_price',selling_price='$selling_price' where product_id='$product_id'"); echo "Product Updated In DB:".$product_id."<br>"; } fclose($csvFile); } else { echo "Upload Failed! Try Again!"; } } else { echo "File Type Not Allowed!"; } } if($_GET['export']=="Export"){ $qry = mysqli_query($link,"SELECT * FROM product_tbl"); while($row = mysqli_fetch_array($qry)) { $data[] = array($row['product_id'],$row['product_name_en'],$row['cost_price'],$row['selling_price'],$row['mrp_price']); } $f = fopen('php://output', 'w'); $delimiter = ","; $filename = "export.csv"; $first = array('Product id','Product_Name','Cost_Price','Selling_Price','Mrp_Price'); fputcsv($f, $first, $delimiter); // loop over the input array foreach($data as $line){ fputcsv($f, $line, $delimiter); } // reset the file pointer to the start of the file fseek($f, 0); // tell the browser it's going to be a csv file header('Content-Type: application/csv'); // tell the browser we want to save it instead of displaying it header('Content-Disposition: attachment; filename="'.$filename.'";'); // make php send the generated csv lines to the browser fpassthru($f); exit(); } ?> <form action="" method="post" enctype="multipart/form-data" id="image-form" class="form-horizontal" > <fieldset> <div class="box span12"> <div class="box-header" data-original-title> <h2><i class="fa fa-edit"></i><span class="break"></span>Bulk Product To Update Price </h2> <a href="bulkpriceupdate.php?export=Export">Export To CSV</a> </div> <div class="box-content"> <div class="control-group"> <label class="control-label">Upload</label> <div class="controls"> ( for ex : bulkpriceupdate.csv - Fields: product id,cost_price,selling_price,mrp_price)<br> <input type="file" class="upload" name="files" id="files" required /> </div> </div> <center> <div class="form-actions no-margin-bottom"> <input type="submit" id="submit-btn" name="submit" value="Save" class="btn btn-primary" /> </div> </center> </div> </div><!--/span--> </fieldset> </form>