我正在处理 csv 文件上传,我需要上传大型 csv 文件,然后需要使用字段映射插入数据库。我正在使用 Jquery 执行此操作,它没有显示任何错误,只是将 url 显示为红色到 firbug。我没有得到什么问题?这是我的脚本。
<script src="js/jquery.form.js"></script>
<script src="js/create_input.js"></script>
<script>
$(document).ready(function() {
$('#UploadForm').on('submit', function(e) {
e.preventDefault();
var value= $("#valS").val();
var host=$('#host').val();
//alert(host);
$(this).ajaxSubmit({
type: "POST",
url: host+"views/excel_file_import.php",
data: {value: value},
success: function(html){
$('#Exceloutput').html(html);
}
});
});
});
$(document).ready(function() {
$("#updatefields").click(function(){
var arrayOfValues = $(".bookDetails select").map(function (i, el) { return $(el).val(); }).get();
var fileName= $("#excelfile").val();
var csvState= $("#state_csv").val();
var host=$('#host').val();
$.ajax({
type: "POST",
url: host+"views/update_fields.php",
data:{str:arrayOfValues, fileName:fileName, csvState:csvState},
success: function(msg){
$('#fieldUpdate').html(msg);
}
});
return false;
});
});
</script>
<?php
$host=$_SERVER['HTTP_REFERER'];
$url=substr($host,0,-9);
?>
<input type="hidden" value="<?php echo $url; ?>" id="host">
<h1 class="page-title">Upload Csv File</h1>
<div class="container_12 clearfix leading">
<div class="grid_12" id="edit-form">
<form action="<?php echo $url; ?>views/excel_file_import.php" method="post" enctype="multipart/form-data" id="UploadForm" class="form has-validation">
<div class="clearfix">
<label for="form-upload" class="form-label">Upload File<em>*</em></label>
<div class="form-input">
<input type="file" size="50" class="text" id="excelfile" name="excelfile" required="required"/>
<input type="hidden" size="50" class="text" id="valS" name="valS" value="1" required="required"/>
</div>
</div>
<div class="form-action clearfix">
<button class="button class-button" type="submit" id="SubmitButton">Upload</button>
<button class="button class-button" type="submit" id="updatefields" name="updatefields">UpdateExcel</button>
</div>
</form>
<div id='fieldUpdate'>
</div>
<div id='Exceloutput'>
</div>
</div>
</div>
这是 excel_file_import.php 代码。
<?php
include("../common/connection.php");
if(isset($_POST))
{
$database= "test2";
$filename = 'test-'.$_FILES['excelfile']['name'];
$value= $_POST['value'];
$copy= move_uploaded_file($_FILES["excelfile"]["tmp_name"],"../files/".$filename);
if($copy)
{ echo "Upload Success";?>
<?php
}
}
?>