我用JavaScript编写了一个脚本,该脚本使我可以从输入文件类型捕获图像。我把它变成URL并保存。到目前为止,一切正常。当我尝试
function values(a){
if (a.length>1){
var imgdata;
var oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("immagine").files[0]);
oFReader.onload = function (oFREvent) {
imgdata = oFREvent.target.result;
var params= "V1="+a[2]+"& V2="+a[3]+"& V3="+a[4]+"& V4="+a[5]+"& V5="+a[6]+"& V6="+a[7]+"& V7="+a[8]+"& V8="+a[9]+"& V9="+a[10]+"& V10="+a[11]+"& V11="+a[12]+"& V12="+a[13]+"& V13="+a[14]+"& V14="+a[15]+"& img="+imgdata;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
}
};
xhttp.open("POST", "./server/AggiuntaBhk.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send( params);
};
include("../../connessione_db/db_con.php"); // Include il file di
connessione al database
session_start();
$v1=$_REQUEST["V1"];
$v2=$_REQUEST["V2"];
$v3=$_REQUEST["V3"];
$v4=$_REQUEST["V4"];
$v5=$_REQUEST["V5"];
$v6=$_REQUEST["V6"];
$v7=$_REQUEST["V7"];
$v8=$_REQUEST["V8"];
$v9=$_REQUEST["V9"];
$v10=$_REQUEST["V10"];
$v11=$_REQUEST["V11"];
$v12=$_REQUEST["V12"];
$v13=$_REQUEST["V13"];
$v14=$_REQUEST["V14"];
$foto=$_REQUEST["img"];
$queryInput="INSERT INTO bhk (Metrica1,Metrica2,Metrica3,Metrica4,Metrica5,Metrica6,Metrica7,Metrica8,Metrica9,Metrica10,Metrica11,Metrica12,Metrica13,Data,Puntoz,Paziente,Foto) VALUES ('$v1','$v2','$v3','$v4','$v5','$v6','$v7','$v8','$v9','$v10','$v11','$v12','$v13','2014-01-01','$v14','BVNVCN97L18C983O','$foto')";
$queryI = mysqli_query($connessione_al_server,$queryInput);
$queryi = "SELECT Foto FROM bhk WHERE Cod_Bhk = '".$Codice."'";
<h1>to Display</h1>
<img id="imgcaricata" class="mySlides" src="'.( $foto["Foto"] ).'" style="height:auto; width:auto;max-width:500px; margin-top:55px;"/>
保存在数据库中的图像是:
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAHgAeAAD/4QBoRXhpZgAATU0AKgAAAAgABAEa ....... ecc
错误是:
net::ERR_INVALID_URL
数据库中的“ Foto”类型为longblob