如何在mysql中插入文件然后可下载 我使用这段代码来显示文件并将其插入mysql中,我选择blob是mysql中文件的类型。它工作正常,但mysql允许您以二进制格式下载它。这是我的代码
<body>
<div class="container">
<form name="addform" action="addfile" method="post" accept-charset="utf-8" onSubmit="return Check();">
<h2>Adding a service</h2><br><br>
<div class="row">
<label>service name : </label><br>
<input type="text" name="name" placeholder="service name" />
</div><br>
<div class="row">
<label>file :</label><br>
<input id="upload" type="file" accept="text/html" size=30 name="fichier" placeholder="service">
</div><br>
<textarea class="form-control" rows=20 cols=10 id="ms_word_filtered_html"></textarea>
<br>
<div class="row">
<input class="btn" type='submit' value='Submit'>
<input class="btn" type='reset' value='Reset'>
<input class="btn" type='button' value='Back' onclick="javascript: location.href='/'">
<br><br>
<label class="msgerr">
<%=msg %>
</label>
</div>
</form>
<script>
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
// use the 1st file from the list
f = files[0];
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {
jQuery( '#ms_word_filtered_html' ).val( e.target.result );
};
})(f);
// Read in the image file as a data URL.
reader.readAsText(f);
}
document.getElementById('upload').addEventListener('change', handleFileSelect, false);
</script>