Page 1 ----------------------------------------html ----------------------------------------
<div class="box-body">
<center>Import <b>Data</b> from CSV file</center><br><br>
<div id="regImageDiv" class="form-group">
<label for="regStaffImage" class="col-sm-5" style="text-align:right">DATA</label>
<div class="col-sm-7" style="text-align:left">
<?php /*"<form class="form-horizontal" action="hex-upload-process.php" method="post" name="upload_csv" id="upload_csv" enctype="multipart/form-data">"*/ ?>
<form class="form-horizontal" action="hex-upload-process-mp.php" method="post" name="upload_csv" id="upload_csv" enctype="multipart/form-data">
<input type="file" id="file" name="file">
<input type="hidden" id="perId" name="perId" value="<?php echo $selectedMonth ?>">
<p class="help-block">Choose <i>.csv </i> file only.</p>
<span id="imageSpan" class="help-block" style="display:none"></span>
</div><br><br><br><br>
<center>
<button type="submit" id="submit" name="Import" class="btn btn-info pull-center" data-loading-text="Loading..." onClick="loading()"><b>IMPORT</b>
</button>
</center>
</br>
<center>
<a href="hex-upload.php?clear=true"><b>CLEAR ALL SCHEDULING DATA</b></a>
</center>
</br>
<center>
<span id="hex-upload-span" name="hex-upload-span" class="help-block" style="visibility:hidden"/>
</center>
</form>
</div>
</div>
------------------------------------------- JS ------------------------------------------
<script type="text/javascript">
function loading(){
//$('#loader').show();
$('#loader').css('visibility', 'visible');
$('#upload_csv').submit();
}
<script>
СТРАНИЦА2 process.php
<?php //Latest build 18/06/2019 11:00AM
ini_set('max_execution_time' , 1200); ini_set('memory_limit','32M'); include ("include/connect.php"); session_start(); $currentDate = date('Y-m-d'); $type = "daily";
//check file if uploaded
if($_FILES["file"]["size"] > 0){
$filenamehistory=$_FILES["file"]["name"];
$filename=$_FILES["file"]["tmp_name"];
//fetch all data in imported csv file by user
$file = fopen($filename, "r"); $x = 1; $csv = ""; while (($getData = fgetcsv($file, 10000, ",")) !== FALSE){ ${"JobNo_".$x} = $getData[0]; ${"Model_".$x} = $getData[1]; ${"ProdQty_".$x} = $getData[2]; ${"SDate_".$x} = $getData[3]; ${"EDate_".$x} = $getData[4]; ${"Status_".$x} = $getData[5]; ${"CurSDate_".$x} = $getData[6]; ${"CurPQty_".$x} = $getData[7]; ${"LineNo_".$x} = $getData[8]; ${"Remark_".$x} = $getData[9]; ${"IsdOnly_".$x} = $getData[10]; ${"Cond_".$x} = $getData[11]; ${"Evap_".$x} = $getData[12];
if($getData[3] != 0){ $dataStartDt = date_create_from_format('j/m/Y', $getData[3]); ${"SDate_".$x} = date_format($dataStartDt, 'Y-m-d'); }else{ ${"SDate_".$x} = "0000-00-00"; } $getData[3] = ${"SDate_".$x};
if($getData[4] != 0){ $dataEndDt = date_create_from_format('j/m/Y', $getData[4]); ${"EDate_".$x} = date_format($dataEndDt, 'Y-m-d'); }else{ ${"EDate_".$x} = "0000-00-00"; }
if($getData[6] != 0){ $dataCurrStartDt = date_create_from_format('j/m/Y', $getData[6]); ${"CurSDate_".$x} = date_format($dataCurrStartDt, 'Y-m-d'); }else{ ${"CurSDate_".$x}
= "0000-00-00"; }
${$getData[3].$getData[0].$getData[6]} = $x;
$csv .= ${"JobNo_".$x}.','.${"Model_".$x}.','.${"ProdQty_".$x}.','.${"SDate_".$x}.','.${"EDate_".$x}.','.${"Status_".$x}.','.${"CurSDate_".$x}.','.${"CurPQty_".$x}.','.${"LineNo_".$x}.','.${"Remark_".$x}.','.${"IsdOnly_".$x}.','.${"Cond_".$x}.','.${"Evap_".$x}."\n";
$x++; } $totaldata = $x; fclose($file);
$csv_filename = "csvfile/".$filenamehistory; $csv_handler = fopen ($csv_filename,'w'); fwrite ($csv_handler,$csv); fclose ($csv_handler); } else{ echo "<script type=\"text/javascript\">alert(\"Invalid File:Please Upload CSV File.\");window.location = \"hex-upload.php\"</script>"; die(); }
, пожалуйста, сначала скопируйте в notepad ++.Этот код использует fopen, fclose, fwrite, fgetcsv
, чтобы понять, как выглядят его данные, в my $ csv.Используйте «,» для разделения столбца «\ n» для разделения строки.
ИЛИ вместо этого вы можете использовать phpexcel