我试图在服务器中保存cvs文件并将它们导入到sql表中。我没有保存文件的问题,但是文件没有导入到表中。
这里是代码
HTML:
<form enctype="multipart/form-data" method="post" id="import_list_form">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" name="import_list_send" value="Upload" />
</form>
和php:
if(isset($_POST['import_list_send'])){
$uploaddir = plugin_dir_path( __FILE__ ) . 'uploads/';
$uploadfile = $uploaddir . basename($_FILES['uploaded']['name']);
$file_imported = $_FILES['uploaded']['name'];
$upload_location = plugin_dir_url( __FILE__ ) . 'uploads/';
$upload_location_final = $upload_location . basename($_FILES['uploaded']['name']);
$delimiter = ',';
echo '<pre>';
if ($_FILES['uploaded']['type'] == 'text/csv'){
move_uploaded_file($_FILES['uploaded']['tmp_name'], $uploadfile);
echo "<p style='float:right;' class='print_msg'>File is valid, and was successfully uploaded in:</p>";
echo "<p style='float:right;' class='print_msg'><a href='$upload_location_final' target='_blank'>" . $upload_location_final . "</a></p>";
mysqli_query($conn, "LOAD DATA INFILE '$upload_location_final' INTO `Table`");
}else{
echo "<p style='float:right;' class='print_msg'>File is not valid! Please make sure you have selected a CSV file.</p>";
}
print "</pre>";
}
任何想法如何让文件上传数据库表?