我搜索了很多网站,但没有找到解决方法
if(isset($_FILES['uploadFile']['name']) && !empty($_FILES['uploadFile']['name'])) {
//Allowed file type
$allowed_extensions = array("jpg","jpeg","png","gif");
//File extension
$ext = strtolower(pathinfo($_FILES['uploadFile']['name'], PATHINFO_EXTENSION));
//Check extension
if(in_array($ext, $allowed_extensions)) {
//Convert image to base64
$encoded_image = base64_encode(file_get_contents($_FILES['uploadFile']['tmp_name']));
$encoded_image = 'data:image/' . $ext . ';base64,' . $encoded_image;
$query = "INSERT INTO images (id, encoded_image) VALUES (NULL, '$encoded_image');";
mysqli_query($con, $query);
echo "File name : " . $_FILES['uploadFile']['name'];
if(mysqli_affected_rows($con) > 0) {
echo "Status : Uploaded";
$last_insert_id = mysqli_insert_id($con);
} else {
echo "Status : Failed to upload!";
}
} else {
echo "File not allowed";
}
}