我想上傳一個csv
。我想要做的是上傳成功時,頁面的顏色(main-div
)變爲綠色。失敗時,將其變爲紅色。我想在同一個php腳本中完成它。上傳成功後,如何將main-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'])) {
echo "<div id='main-div' class='block-content block-content-full bg-danger text-white-op'>";
$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 "<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 "<div class='block-content block-content-full bg-city text-white-op'>";*/
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);
?>
<script type="text/javascript">
$('#main-div').addClass('block-content block-content-full bg-success text-white-op');
</script>
<?php
/* echo "<div class='block-content block-content-full bg-success text-white-op'>";*/
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>";
只需將ac當上傳完成後,對上面的div進行了上傳,並使用綠色對它們進行了樣式設計 – Krish
–
@sagar它不工作 – colombo