我还有其他几个相同的功能正常运行,但我无法使用最后一点(照片被'上传'不存储在数据库中)。任何帮助都将非常感激。 我理解mysql语句是一个已弃用的版本,将会更改。
Ajax功能
function uploadProLicense5() {
var ajax = new XMLHttpRequest();
var dataFive = new FormData();
dataFive.append("professionalLicensePhotoFifthProivder", document.querySelector("#professionalLicensePhotoFifthProivder").files[0]);
ajax.open("POST", "home.php");
ajax.onreadystatechange = function() {
if (ajax.readyState === 4) {
if (ajax.status === 200) {
// OK
$('#success_prolicense5').fadeIn().html("Photo Saved");
setTimeout(function(){
$('#success_prolicense5').fadeOut("Slow");
}, 2000);
// here you can use the result (ajax.responseText)
} else {
// not OK
alert('failed to upload photo, please try again');
}
}
};
ajax.send(dataFive);
}
HTML
<div class="well col-lg-4 col-lg-offset-4 col-md-4 col-md-offset-4 col-sm-10 col-sm-offset-1 col-xs-10 col-xs-offset-1" id="professionalphotoRow5">
<div class="text-center">
<label>Upload professional license photo:</label>
</div>
<div class="text-center">
<label id="label5thproviderPro">for 5th provider</label>
</div>
<div class="col-sm-offset-4 col-xs-offset-4">
<input name="professionalLicensePhotoFifthProivder" id="professionalLicensePhotoFifthProivder" class="filestyle" data-input="false"
type="file" accept="image/*">
</div>
<?php
$savedTxt = "Photo Saved";
$notSavedTxt = "Photo Not Saved";
if (!empty($userRow[pro_license_photo_provider_five])) {
echo "<i class='glyphicon glyphicon-ok col-sm-offset-4 col-xs-offset-4' style='color: greenyellow;'>" . "</i> " . $savedTxt;
}
?>
<br>
<div class="col-sm-offset-4 col-xs-offset-4">
<input id="saveProfessionalPhoto5" type="button" class="btn btn-default"
name="saveProfessionalPhoto5" onclick="uploadProLicense5()"
value="upload photo" style="background-color: #1d2b5c; color: white"/>
</div>
<span id="success_prolicense5" class="text-success col-sm-offset-4 col-xs-offset-4"></span>
</div>
PHP
$db_pro_license_img_provider_five = addslashes(file_get_contents($_FILES['professionalLicensePhotoFifthProivder']['tmp_name']));
$pro_image_data_provider_five = base64_encode($userRow[pro_license_photo_provider_five]);
$pro_data_provider_five = substr($pro_image_data_provider_five, strpos($pro_image_data_provider_five, ","));
if(!empty($db_pro_license_img_provider_five)){
$sql = "UPDATE `wp_form` SET
`pro_license_photo_provider_five`='$db_pro_license_img_provider_five'
WHERE id =" . $_SESSION['user'];
mysql_query($sql) or die(mysql_error());
$res = mysql_query("SELECT * FROM wp_form WHERE id=" . $_SESSION['user']);
$userRow = mysql_fetch_array($res);
}
这是我的网络请求
然后我的空洞:(