在下面的代碼中,我試圖上傳csv file.its working.what我想知道的是,當csv成功上傳爲綠色,並且當它沒有上傳爲紅色時,我可以如何更改main-div的顏色?改變裏面的div的顏色,如果其他?
這裏是我的代碼
<div id="main-div" class="content bg-gray-lighter">
<h3 class=" pull-right"><a href="<?php echo $one->assets_folder; ?>/download/sample_csv.csv"><span class="label label-warning"><i class="fa fa-download "></i> Download Sample Format Here <i class="fa fa-file-excel-o "></i> </span></a></h3>
<?php
include "../classes/connection.php"; //Connect to Database
//Upload File
if (isset($_POST['submit'])) {
$deleterecords = "UPDATE TABLE data"; //empty the table of its current records
mysql_query($deleterecords);
$product = $_POST['product'];
$courier = $_POST['courier'];
$billmonth = $_POST['billmonth'];
$billyear = $_POST['billyear'];
$billrun = $_POST['billrun'];
$dispatchtype = $_POST['dispatchtype'];
$Received_Date=$_POST['Received_Date'];
if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
echo "<div id='main-div' class='block-content block-content-full bg-success text-white-op'>";
echo "<p>Displaying contents:</p>";
echo "<p>Product - <strong style='color: #ffc128'>".$product. " </strong> Service Provider - <strong style='color: #ffc128'>".$courier. "</strong> Bill Month - <strong style='color: #ffc128'>".$billmonth. " </strong> Bill Year - <strong style='color: #ffc128'>".$billyear. "</strong> Bill Run- <strong style='color: #ffc128'>" .$billrun. " </strong> Dispatch Type - <strong style='color: #ffc128'>".$dispatchtype."</strong></p><br/>";
echo "<span style='color:#feffa4'>";
readfile($_FILES['filename']['tmp_name']);
echo "</span>";
}
//Import uploaded file to Database
$handle = fopen($_FILES['filename']['tmp_name'], "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$linecount++ == count(file('filename.csv'));
$data[2] = date('Y-m-d', strtotime($data[2]));
$data[5] = date('Y-m-d', strtotime($data[5]));
if (($product==$data[0]) && ($courier==$data[1]) && (strcasecmp($billmonth,$data[6])==0) && ($billyear==$data[7]) && ($billrun==$data[8]) && ($dispatchtype==$data[9])) {
$import = "INSERT into data(Product,Courier,Received_Date,Acc_No,Received_By,Delivered_Date,Month,Year,Bill_Run,Dispatch_Type,Status,Bounce_Code) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[9]','$data[10]','$data[11]')";
}
else {
echo " <br/> <br/>Data Error.<br/>";
echo " <br/><br/><a href='javascript:history.go(-1)' class='btn btn-sm btn-primary'><i class='si si-action-undo'></i> Go Back and Upload Again</a> <br/> <br/>";
}
mysql_query($import) or die(mysql_error());
}
fclose($handle);
?>
<?php
echo "<br/><br/><br/>";
print "$linecount Records have been Imported ";
echo " <br/><br/><a href='javascript:history.go(-1)' class='btn btn-sm btn-primary'><i class='si si-action-undo'></i> Go Back and Upload Again</a> <a href='index.php' class='btn btn-sm btn-primary'><i class='si si-home'></i> Home</a> <br/> <br/>";
//view upload form
echo "</div>";
} else { ?>
有一百萬個答案。但更重要的是似乎對代碼的基本架構有所評論:您應該開始分離輸入和創建輸出的處理。您首先處理並收集所有數據,然後開始創建輸出,以便讓所有數據都可用。開始將這些單獨的方面放入單獨的文件中的額外點... – arkascha